How to write the output of matlab iteration results of many equations in excel in row by row specifying the starting row?

조회 수: 5 (최근 30일)
Hi, I have a code that is as follows (this is simplified):
-----------------------------
for Xref1=0:0.1:1 % Loop through the range of inputs
Xref1;
Hi=Xref1*10;
Lo=Xref1*5;
file_location=['C:\Users\Desktop\data.xls'];
col_header={'Hi','Lo',};
out_put={Hi(:),Lo(:)};
xlswrite(file_location,col_header,'Sheet1','A1');% Prints column headers
xlswrite(file_location,out_put,'Sheet1','A2'); % Prints outputs
end
----------------
This only prints and saves the last iteration in row A2.
The objective is to save all the iteration results starting from A2. Is anyone able to suggest how this can be possible?
Thanks

채택된 답변

VBBV
VBBV 2023년 7월 31일
편집: VBBV 2023년 7월 31일
k = 1;
for Xref1=0:0.1:1 % Loop through the range of inputs
Xref1;
Hi=Xref1*10;
Lo=Xref1*5;
out_put(k,:)={Hi,Lo};
k = k+1;
end
% outside of loop
file_location=['C:\Users\Desktop\data.xls'];
col_header={'Hi','Lo',};
xlswrite(file_location,col_header,'Sheet1','A1');% Prints column headers
xlswrite(file_location,out_put,'Sheet1','A2'); % Prints outputs
  댓글 수: 1
VBBV
VBBV 2023년 7월 31일
편집: VBBV 2023년 7월 31일
Inside the loop the Hi and Lo values are scalar , you need to create vector of values and write them Excel file sheet over a range of cells e.g. A2 : B6 . A better function writing to Excel file is to use *writematrix* instead of *xlswrite*

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by