필터 지우기
필터 지우기

how to read and plot excel file

조회 수: 1 (최근 30일)
Fadzli
Fadzli 2017년 6월 12일
댓글: Walter Roberson 2017년 6월 12일
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개)

카테고리

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