필터 지우기
필터 지우기

How to keep adding rows in a structure inside a for loop

조회 수: 67 (최근 30일)
Matlab_Student
Matlab_Student 2018년 1월 24일
답변: Matlab_Student 2018년 1월 25일
The screenshot below is what I want to accomplish. I have a for loop that, for each organ name, calculates the coverage, maxdose, and meandose. I would like to create an empty structure, then inside the for loop, for each iteration, store the corresponding information in a row, and then adds on to it for the next iteration. How would I do this?
psuedo code:
create a struct called PatientInfo with fieldnames: 'name', 'coverage', 'maxdose', and 'meandose'
for i = 1:4
calculates the corresponding coverage, maxdose & meandose;
writes these values to a row
end

답변 (2개)

Matlab_Student
Matlab_Student 2018년 1월 25일
Answering my own question
In the loop:
structrow = structrow + 1;
PatientInfo(structrow).name = name_val;
PatientInfo(structrow).coverage = coverage_val;
PatientInfo(structrow).maxdose = maxdose_val;
PatientInfo(structrow).meandose = meandose_val;

Walter Roberson
Walter Roberson 2018년 1월 24일
편집: Walter Roberson 2018년 1월 24일
PatientInfo = struct('name', {'BodyAuto', 'BrainStem', 'SpinalCord', 'Parotid_R'}, 'coverage', [], 'maxdose', [], 'meandose', []);

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by