How can i store multiple data into same excel file ?

6 views (last 30 days)
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,

Answers (1)

Matt Tearle
Matt Tearle on 22 Mar 2011
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);
  2 Comments
sandeep
sandeep on 23 Mar 2011
My matlab program asks for input file as following:
prompt1={'Enter input file name (without extension [.mat]): '};
fname1 = inputdlg(prompt1);
After selecting this it runs the remaining code and displays output such as surface area, time , voltage. I am storing the values related to these variables in a excel file using xlswrite. When i run the matlab program second time, the output data related to the another input file that I have selected should be stored in the same excel file at different locations .
Thank you.
regards,

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!