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

2 Ansichten (letzte 30 Tage)
J Culpepper
J Culpepper am 16 Aug. 2016
Kommentiert: J Culpepper am 19 Aug. 2016
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 Kommentare
J Culpepper
J Culpepper am 18 Aug. 2016
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 am 18 Aug. 2016
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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Image Analyst
Image Analyst am 17 Aug. 2016
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 am 19 Aug. 2016
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');

Community Treasure Hunt

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

Start Hunting!

Translated by