How to export to csv in multiple rows instead of all columns?

조회 수: 2 (최근 30일)
J Culpepper
J Culpepper 2016년 8월 16일
댓글: J Culpepper 2016년 8월 19일
Hello all, I am developing a code to export a long (>32,000 values) comma separated value char variable set of ASCii scope measurements into a comma separated value, which is saved in Excel. Excel limits its # of columns to 16,384, but rows are limited to 1,048,576. For this reason I want to either split the data into multiple rows, or save all data into column A as rows. This is my export code:
function csvExportData(channel,csvData)
if (channel == 1)
splitData = strsplit(csvData,','); %remove commas
exportData = mat2dataset(splitData); %creates dataset array
export(exportData,'file','scopeDataTestCh1.csv','Delimiter',',','WriteVarNames',false); %write to scopeDataTest.csv
end
end
csvData is in the form: 2.79E-02,1.63E-02,5.8E-03,-2.6E-03,-1.11E-02............... where the values vary, and the length varies, sometimes being very long. I can not have a limit to the length of the data, as its important that I can get all the y-values for the scope's measurement (up to 80 GSa/s).
Thanks in advance for any tips y'all can provide.
  댓글 수: 3
J Culpepper
J Culpepper 2016년 8월 18일
Hey John, I would prefer to save in MATLAB, as I will be doing my post-processing in MATLAB. It's just that whenever I try to save the data in MATLAB, it automatically puts it into Excel. This is the reason I was basing my question around Excel. An example of something I will be doing is taking a waveform, and integrating it in MATLAB then scaling it to match a similar waveform. However, once I can get the data into another program, I hope to be able to do any sort of post-processing typical of laboratory testing.
J Culpepper
J Culpepper 2016년 8월 18일
Would you suggest simply exporting the long string of data into another MATLAB program where I will perform any post-processing? It seems this is a better solution than exporting from MATLAB at all. Thank you for your suggestion.

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2016년 8월 17일
Did you try this to export into an Excel workbook:
% Create sample data
csvData = sprintf('%.2f', rand());
for k = 1 : 7000
csvData = sprintf('%s,%.2f', csvData, rand());
end
% Now, csvData is a 35,004 character long character array
% of numbers separated by commas.
% Now we have sample data and we can begin.
% Now remove commas and transpose.
splitData = strsplit(csvData,',')';
% splitData is a 70001 cell array in a column.
% Write it to Excel into column A
xlswrite('delete me.xlsx', splitData, 'Results', 'A1');
% Now all 7001 numbers will be in rows 1-7001 of the workbook column A.

Image Analyst
Image Analyst 2016년 8월 19일
J, you say "I would prefer to save in MATLAB, as I will be doing my post-processing in MATLAB" so then just use save(), like
% Now remove commas and transpose.
splitData = strsplit(csvData,',')';
% Save to a .mat file in proprietary MATLAB format.
save(someFileName, 'splitData');
  댓글 수: 1
J Culpepper
J Culpepper 2016년 8월 19일
This is what I ended up doing, thank you very much for your help, I.A.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by