Filter löschen
Filter löschen

How to save output results for loop iterations

3 Ansichten (letzte 30 Tage)
Eslam
Eslam am 8 Mär. 2023
Beantwortet: Steven Lord am 8 Mär. 2023
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.

Antworten (1)

Steven Lord
Steven Lord am 8 Mär. 2023
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.

Kategorien

Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by