Saving data to EXCEL
3 ビュー (過去 30 日間)
古いコメントを表示
I'm using MATLAB to analyze smaller windows of data in a large excel file. the code runs for one window, I can make adjustments (I've put in a manual override) and rerun it for that window before going on to the next window. Also, for each window I'm calculating means and standard deviations. What I want to do is export those means and standard deviations into a second excel file where those numbers for each successive window would be saved to the next row down. So, if Window 1 values are saved in row 10, Window 2 values would saved in row 11, Window 3 would be saved in row 12, etc.
This is the end part of the code that I'm having trouble with (xlswrite is at the very bottom). I'm not very familiar with MATLAB so it might just be a format issue that I'm having. 'j' is the number of the window that is being looked at.
Thanks!
%find average RWT value for window
disp('LOCATION')
disp(LOCATION(wstarti(j)))
disp('AVERAGE RWTrfu VALUE')
disp(mean(r(greatvec==1)))
disp('STANDARD DEVIATION RWTrfu VALUE')
disp(std(r(greatvec==1)))
disp('AVERAGE TURBrfu VALUE')
disp(mean(t(greatvec==1)))
disp('STANDARD DEVIATION TURBrfu VALUE')
disp(std(t(greatvec==1)))
disp('AVERAGE CHLArfu VALUE')
disp(mean(ch(greatvec==1)))
disp('STANDARD DEVIATION CHLArfu VALUE')
disp(std(ch(greatvec==1)))
%define variables to save in results file
RESULTSLOCATION=LOCATION(wstarti(j));
DATESTART=(DATE(wstarti(j)));
DATEEND=(DATE(wendi(j)));
MEANR=(mean(r(greatvec==1)));
STDR=(std(r(greatvec==1)));
MEANT=(mean(t(greatvec==1)));
STDT=(std(t(greatvec==1)));
MEANCH=(mean(ch(greatvec==1)));
STDCH=(std(ch(greatvec==1)));
disp(' close excel file & press return to continue')
%pause
startnum=startnum+1;
%goodvec(find(isfinite(overide)))=overide(find(isfinite(overide)));
GOODVEC(wstarti(j):wendi(j))=goodvec;
%save data
xlswrite(filename,GOODVEC,1,'I10');
xlswrite(filename,GREATVEC,1,'K10');
% file that results are saved to
dirname='C:\Users\kdl\Desktop\Tracer Study Results';
resultsfilename='tracer_study_5_results.xlsx';
xlswrite(resultsfilename,RESULTSLOCATION,1,'A10:num2str(j)');
xlswrite(resultsfilename,DATESTART,1,'B10:num2str(j)');
xlswrite(resultsfilename,DATEEND,1,'C10:num2str(j)');
xlswrite(resultsfilename,MEANR,1,'D10:num2str(j)');
xlswrite(resultsfilename,STDR,1,'E10:num2str(j)');
xlswrite(resultsfilename,MEANT,1,'F10:num2str(j)');
xlswrite(resultsfilename,STDT,1,'G10:num2str(j)');
xlswrite(resultsfilename,MEANCH,1,'H10:num2str(j)');
xlswrite(resultsfilename,STDCH,1,'I10:num2str(j)');
end
startnum = 1;
0 件のコメント
回答 (1 件)
Kevin Holst
2012 年 2 月 6 日
Are you having problems at this line?
xlswrite(resultsfilename,RESULTSLOCATION,1,'A10:num2str(j)');
If so, I would bet that the problem is that you're actually wanting to do something like this:
xlswrite(resultsfilename,RESULTSLOCATION,1,['A' num2str(j+10)]);
I don't have too much experience with xlswrite either, but the syntax for that line is definitely incorrect. Same goes for each subsequent line.
2 件のコメント
Benjamin Schwabe
2012 年 2 月 6 日
Hello,
I assume you should have a problem with each xlswrite line above.
Correct is, 'A10:num2str(j)' is an illegal "location" string in the table.
Instead of 'A10:num2str(j)', it should be
['A10:A' num2str(j+10)]
this will give something like 'A10:A20'.
Make sure, that the vectors you are writing into these fields have the proper length.
Kevin Holst
2012 年 2 月 7 日
I assumed that it was a scalar value that she wants to write to her excel sheet, since j is the window number that her program is on.
参考
カテゴリ
Help Center および File Exchange で Data Import from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!