How to save output results for loop iterations

조회 수: 2 (최근 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 CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by