Adding Element based on Condition to Structure with For Loop
이전 댓글 표시
I have a structure that has a series of numbers in one of it's fields, the CurrentTrainingTrialRatio, and I am trying to iterate through a for loop to extract the SliderError and the TrialNumber when the CurrentTrainingTrialRatio is equal to 1.8125 or 1.875. Instead of populating the structure field with just the SliderError values for those ratios, it seems to be including all of them. I'm not sure why this is happening because when I test my logical comparisons individually they seem to work as expected.
% Convert to Structure
MasterDataMeasurement = table2struct(MasterDataMeasurement,"ToScalar",true);
MasterDataMeasurementSlowRatios = struct('SliderError',[],'TrialNumber',[]);
SlowRatiosIndexCounter = 1;
for i=1:height(MasterDataMeasurement.TrainingTrialsBool)
if MasterDataMeasurement.TrainingTrialsBool(i) == 1
if MasterDataMeasurement.CurrentTrainingTrialRatio(i) == 1.8125 | 1.875
MasterDataMeasurementSlowRatios.SliderError(SlowRatiosIndexCounter) = MasterDataMeasurement.SliderError(i);
SlowRatiosIndexCounter = SlowRatiosIndexCounter + 1;
end
end
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!