Adding Element based on Condition to Structure with For Loop
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!