if condition based on coefficients/problem parameters of cfit

1 view (last 30 days)
Hi, I'm trying to create a nested if loop, performing various actions dependant on whether coefficients/problem parameters exist in a cfit I have for a set of data. For example, for an event X, which can happen up to 3 times, I want to carry out a different action for each time X occurs;
for ii=(1:n)
if any(strcmp(cfit,'X1'))==0
Do action 1
if any(strcmp(cfit,'X2'))==0
Do action 2
if any(strcmp(model_e,'X3'))==0
Do action 3
end
end
end
other unrelated action
end
So action 3 only occurs if X1, X2, & X3 are present. When the condition is not met, i.e. if X3 doesn't occur, I would at this point like to exit the if part of the loop above, but not the entire for loop, as the process would need to occur for the next iteration.
The issue is that when I try and do this as explained above, if the condition is not met, i.e. X3 does not exist as a coefficient, this causes an error; 'The name 'X3' is not a coefficient or problem parameter....etc etc'. Thus it seems that my conditions allow actions to be carried out when met, but cause an error when not met (if the coefficient doesn't exist.
In summary, I would like to create an if condition based on whether a coefficient exists in my cfit.
Please let me know if more details are required, and thank you in advance.

Answers (1)

Steven Lord
Steven Lord on 3 Aug 2018

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!