I want to store tables in a for loop to excel

9 ビュー (過去 30 日間)
Christian Wetzel
Christian Wetzel 2022 年 10 月 22 日
回答済み: Christian Wetzel 2022 年 10 月 25 日
Hello all
I have a force calculation of a car and get tables out for different load cases. How do I manage to store all the tables in the for loop in an excel one below the other.
for
.....
%The variable quantities that change are: Fuwf_F_V,Fuwr_F_V,Fuw_F_V,Flwf_F_V,Flwr_F_V,Flw_F_V, %Fpr_F_V,Flw_pr_F_V,Ftr_F_V
Fahrwerksstabkraefte_rear = {'Betrag';'Vektor X rear';'Vektor Y rear';'Vektor Z rear'};
Forces_rear=table(Fahrwerksstabkraefte_rear, ...
Fuwf_F_V,Fuwr_F_V,Fuw_F_V,Flwf_F_V,Flwr_F_V,Flw_F_V, Fpr_F_V,Flw_pr_F_V,Ftr_F_V);
T2=rows2vars(Forces_rear,"VariableNamesSource",'Fahrwerksstabkraefte_rear')
writetable(T2,'Forces_rear.xls');
disp('Forces Rear --> calculated and safed')
end
Matlab displays it correctly in the Command Window. It should be saved exactly below each other
Thanks for Help!

採用された回答

J. Alex Lee
J. Alex Lee 2022 年 10 月 22 日
Assuming the columns in the table are always the same, and you generate multiple versions of a table in the loop, and want to save all of them in a single excel sheet, this is how I deal with that situation in my day-to-day: store the tables in a cell array, then vertcat them all later into a single table to write to file:
N = 4
TablesCell = cell(N,1)
for i = 1:N
tmp = array2table(rand(randi(10),5)); % generate some table
TablesCell{i} = tmp; % save to cell array
end
T = vertcat(TablesCell{:});
writetable(T,filename)
  1 件のコメント
Christian Wetzel
Christian Wetzel 2022 年 10 月 24 日
Thank you very much for the answer!The numbers are repeated in the rows of the table. In my calculation, they are different for each table.

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

その他の回答 (1 件)

Christian Wetzel
Christian Wetzel 2022 年 10 月 25 日
Thank you very much for the answer!The numbers are repeated in the rows of the table. In my calculation, they are different for each table.

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by