How to save data in for loop to excel

11 ビュー (過去 30 日間)
Jidapa Adam
Jidapa Adam 2022 年 1 月 14 日
コメント済み: Walter Roberson 2022 年 1 月 14 日
I have 2 value in loop show that
T0 = [1035 1200];%K
for i = 1:length(T0)
L0 = [0 5e-6] ;%m
yi0 = [1 0 0] ;%molfrac(ya0 yb0 yc0)
P0 = 162.*yi0 ;%kPa
v0 = 2.037e-3 ;%m3/s (volumetric flowrate)
R = 8.314e-3 ;%(kPa*m3)/(kmol*K)
Fi0 = (P0.*v0)./(R.*T0(i)) ;%[Fa Fb Fc][mol/s mol/s mol/s]
Var0 = [Fi0 T0(i)] ;
[L ,Vary] = ode45(@Try_loop,L0,Var0) ;
end
So I want to save every value i in different file in excel for example when i = 1035 and code run to end then save result calculate of 1035 in excel. I don't know how to save it not to overlap on the same value.
  2 件のコメント
Walter Roberson
Walter Roberson 2022 年 1 月 14 日
Do you want 1035 different files? Do you want 1035 different sheets in the same file? Do you want (1035 * 3) columns in the same sheet, with the columns being different length? Do you want a single time column followed 1035 pairs of columns the same length as each other?
Jidapa Adam
Jidapa Adam 2022 年 1 月 14 日
I want 1035 different sheets in the same file.

サインインしてコメントする。

採用された回答

David Sanchez
David Sanchez 2022 年 1 月 14 日
Hi Jidapa, type in your matlab terminal
doc xlswrite
This will give you lots of information about how to do it.
As an example, to write data given by the variable "A" in sheet "2" starting in cell "E1", you just use the following code:
filename = 'testdata.xlsx';
A = {'Time','Temperature'; 12,98; 13,99; 14,97};
sheet = 2;
xlRange = 'E1';
xlswrite(filename,A,sheet,xlRange)
In your case, "sheet = i" should work, simply adapt the rest of the example to your needs ;)
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 1 月 14 日
These days we would recommend writetable() or writematrix(), with the 'Sheet' parameter.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by