フィルターのクリア

How to save output results for loop iterations

3 ビュー (過去 30 日間)
Eslam
Eslam 2023 年 3 月 8 日
回答済み: Steven Lord 2023 年 3 月 8 日
Hello, I am trying to make a loop that will iterate based on xlsx table and I want to save the result from each itetarion in a table (workspace).
tbl = readtable('Table.xlsx');
Hs = table2array(tbl (:,8));
Ws = table2array(tbl (:,6));
Mwd = table2array(tbl (:,9));
Tp = table2array(tbl (:,10));
%Start=0,Step=30,End=360
s=30;
for x=0:s:360
MWDD = table2array(varfun(@(a)((a>=x) & (a<(x+s))), tbl(:,9)));
MWD = tbl(MWDD,:);
end
Thank you for any help.

回答 (1 件)

Steven Lord
Steven Lord 2023 年 3 月 8 日
Rather than converting from a table to an array to perform your operations, I think what you want to do is to discretize the 9th variable in your table to determine into which bin of data each element falls. Once you have those bin/group numbers if you want to operate on each group in turn use groupsummary, grouptransform, or some other grouping function.
Oh, I just noticed that this is tagged with release R2017b. In that case neither groupsummary nor grouptransform are available (introduced in releases R2018a and R2018b respectively.) In that case look at splitapply. I'd still use discretize but that's because I'm more familiar with it; there is also a more general findgroups function that you could use if you may need to generalize to non-numeric and non-categorical data in the future.

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by