How can i store multiple data into same excel file ?
2 次查看(过去 30 天)
显示 更早的评论
Hello all,
I am trying to store multiple data from m-file into same excel file.
my program selects a file and displays the corresponding outputs.
After that I am using the following to store into excel data:
%create the cell array containing the column headers
columnHeader = {'plotted points_time','plotted points_voltage', 'surfacearea1','surfacearea2'};
%write the column headers first
xlswrite('C:\Documents and Settings\ototemp-u\Desktop\myfile.xlsx', columnHeader );
%write the data directly underneath the column headers
xlswrite('C:\Documents and Settings\ototemp-u\Desktop\myfile.xlsx', t(record2),'Sheet1','A2');
xlswrite('C:\Documents and Settings\ototemp-u\Desktop\myfile.xlsx',Z2(record2),'Sheet1','B2');
winopen('C:\Documents and Settings\ototemp-u\Desktop\myfile.xlsx')
I want the program to store data from different selected files into 1 excel sheet.
Please help me out.
Regards,
0 个评论
回答(1 个)
Matt Tearle
2011-3-22
I'm going to assume that the issue is that you want to run this code again later (with different data), so you don't necessarily know, when you run it that second time, how much data is already in the xls file. In that case, a simple fix is to use exist to see if the xls file already exists. If so, use
[~,~,raw] = xlsread(file);
rowoffset = size(raw,1);
to work out how many rows to skip. (Set rowoffset = 0 is the file doesn't exist.)
Then use num2str to make the Excel cell references for writing. Eg
Cref = ['B',num2str(rowoffset+2)];
xlswrite(...,Cref);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!