How can i store multiple data into same excel file ?

조회 수: 2 (최근 30일)
sandeep
sandeep 2011년 3월 22일
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,

답변 (1개)

Matt Tearle
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);
  댓글 수: 2
sandeep
sandeep 2011년 3월 23일
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,
Matt Tearle
Matt Tearle 2011년 3월 23일
OK, so what I suggested should work.

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

카테고리

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