Matlab Batch processing .csv file -
i dealing info analysis .csv file using matlab. have analyse info hundreds of .csv file using same formula files. output info stored in 1 matrix (nrow , ncolumn).
i have problem where, when computation finished, first column of matrix gives right reply while rest of columns give wrong answer. can help me solve problem?
here code.
%% importing csv file selected column files=dir('*.csv'); r=1:length(files); lhr=importcsv(files(r).name); %% calculation of smd % define these value taw=-216; raw=-129; % first row of soil wet deficit j=1 smd(j,r)=(lhr.rain(j)-lhr.pet(j)); if smd(j,r)>0; smd(j,r)=0; elseif smd(j,r)<raw; smd(j,r)=(lhr.rain(j)-(lhr.pet(j)*((taw-smd(j-1))/(taw-raw)))); end end %for next smd calculation o=2:(numel(lhr.rain)); smd(o,r)=smd(o-1)+(lhr.rain(o)-lhr.pet(o)); % smd conditions if smd(o,r)>0; smd(o,r)=0; elseif smd(o,r)<raw; smd(o,r)=smd(o-1)+(lhr.rain(o)-(lhr.pet(o)*((taw-smd(o-1))/(taw-raw)))); end end end
change 3rd loop next code. should give right answer.
%for next smd calculation o=2:(numel(lhr.rain)); smd(o,r)=smd(o-1,r)+(lhr.rain(o)-lhr.pet(o)); % smd conditions if smd(o,r)>0; smd(o,r)=0; elseif smd(o,r)<raw; smd(o,r)=smd(o-1,r)+(lhr.rain(o)-(lhr.pet(o)*((taw-smd(o-1,r))/(taw-raw)))); end end end i shall explain here. smd 2 dimensional matrix. in 3rd loop of code, mentioned vector [smd(o-1)]. have changed [smd(o-1,r)]. hope should give right answer.
matlab csv batch-processing
No comments:
Post a Comment