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

3 ビュー (過去 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 Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by