Changing WriteTable inputs for every loop and changing the "sheets" value for every loop

Hey there,
So two fold, one I am trying to change the input varible each iteration in a for loop and the number of sheets. I am wanting the filename to be my 7 seperate Atl files (Alt_300, Alt_400, Alt_500...ect). Then I am wanting the value of in "sheets" varible place to go from 1 to 7 (creating a total of 7 sheets once the program has run). Alterntively I could just not use eval and just overwrite "alt" varible each time but still raises the issue of the sheets varible. There is problem a straight forward way of doing all of this but I am at a loss.
Thank you!

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 8 月 7 日
i_vals = 300:100:900;
for i_idx = 1 : length(i_vals)
i = i_vals(i_idx);
filename = sprintf('Alt_%d.xlsx', i);
ind = find(altitude >= i & altitude < i+100); %not <= !!
alt = table(those variables);
sheets = sprintf('Alt_%d', i);
writetable(alt, filename, 'sheet', sheets, 'Range', 'A1');
end

1 件のコメント

nathan stallworth
nathan stallworth 2021 年 8 月 13 日
Thank you! This is not exactly what I wanted but got me headed in the correct direction.

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2021 年 8 月 7 日

コメント済み:

2021 年 8 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by