Iteratively fill structure with custom class objects

조회 수: 2 (최근 30일)
Metin Akyol
Metin Akyol 2022년 1월 19일
댓글: Matt J 2022년 1월 19일
I would like to run a loop throgh a table that takes values from each row and uses them as input parameters for custom classes and adds them to a structure so I can use them later. This is what I have so far:
rows = height(table);
for row = 1:rows
strat_1 = custom_class(table2array(table(row,1)),table2array(table(row,1)));
end
That is, strat_1 is supposed to be part of the loop and added to a structure in each iteration

답변 (1개)

Matt J
Matt J 2022년 1월 19일
편집: Matt J 2022년 1월 19일
I'm puzzled as to why your custom_class() constructor requires the same input argument twice, but this is how I'd do it.
rows = height(table);
A=table2array(table);
clear strat
for row = rows:-1:1
input=A(i,:);
strat(i) = custom_class(input,input);
end
  댓글 수: 2
Metin Akyol
Metin Akyol 2022년 1월 19일
Perfect, thank you so much. (the input argument was a typo, that should be table(row,2) at the 2nd position).
Matt J
Matt J 2022년 1월 19일
You're welcome, but if your question has been addressed, please Accept-click the answer.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by