how to read and plot excel file

1 次查看(过去 30 天)
Hi all,
I want to read an excel file, use the data to calculate, then plot the result in result file. I have this code so far;
namefile=input('Name the file for your result:','s');
result_file_name=sprintf('%s%s',namefile,'.xlsx');
save result_file_name;
FileNamE=sprintf('%s %s','Your result file will be name as:',result_file_name);
disp(FileNamE)
xlswrite(result_file_name,1);
excelfile=sprintf('%s%s','C:\Users\This Laptop\Desktop\MATLAB\',result_file_name);
Excel = actxserver ('Excel.Application');%excel always opened so that works faster
File=excelfile;
Excelworkbook=Excel.workbooks.Open(File);
input_data=xlsread('inputdata_size.xlsx',1,'(A2:AG553)');
[nofinput]=length(input_data(:,1)); %to calculate number of rows
start=input('press enter to start');
for ww=1:552;
ii=input_data(ww,:);
run_1=ii;
mass=run_1(:,9); %read from excel file, column#9
density=run_1(:,10); %read from excel file, column#10
step_number=552;
[uu]=step_number;
[cc]=2;
AAA=zeros(uu,cc);
clear uu cc
size=(2*((3*mass)/(4*density*pi))^(1/3));
AAA(ww,:)=[size];
end
header_result_file_name={'size'};
xlswrite1(result_file_name,header_result_file_name,ww,'A1');
xlswrite1(result_file_name,AAA,ww,'A2');
Excelworkbook.Worksheets.Item(ww).Range('A1:B1').Interior.ColorIndex = 40;
Excelworkbook.Save
Excelworkbook.Close(false)
Excel.Quit;
delete(Excel);
toc
But the problem is, the results plotted in different sheet in excel file. There are 552 sheets, 1 result per sheet. I'm expecting to have a list of 552 results in just one column (in 1 sheet). I guest something wrong with xlswrite1 command, or maybe with 'for' loop, but I'm not sure where is it. Please help. Thanks

采纳的回答

Walter Roberson
Walter Roberson 2017-6-12
You have
xlswrite1(result_file_name,header_result_file_name,ww,'A1');
The third parameter, which you pass as ww, is the sheet information. You are changing ww each time, so it is going to write to different sheets each time.
"I'm expecting to have a list of 552 results in just one column"
Don't write the header inside the loop, write it once first. After that, write to sheet 1 each time, to cell sprintf('A', ww+1)
  2 个评论
Fadzli
Fadzli 2017-6-12
Thanks @Walter Roberson.
"Don't write the header inside the loop, write it once first. After that, write to sheet 1 each time, to cell sprintf('A', ww+1)"
Can you explain or show further how to write to sheet 1 each time...any specific command to use? Thanks
Walter Roberson
Walter Roberson 2017-6-12
xlswrite1(result_file_name, header_result_file_name, 1, sprintf('A%d', ww+1));

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by