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);
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!