How to save output results for loop iterations
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!