Clear Filters
Clear Filters

Saving vector result from each loop if solution is correct.

5 views (last 30 days)
Let's say DMP.m uses fsolve and output a solution vector, named xx. It can be `Equation solved', 'No solution found', or 'Equation solved but inaccuracy possible.'
I want to store the vector if it tells `Equation solved'.
So for example, my code is
for r=1:10
DMP
if exitflag==1
xxx(r,:)=xx
end
end
Unrecognized function or variable 'r'.
But Matlab gives me the error message: Unrecognized function or variable 'r'.
Could you help me the coding?

Accepted Answer

Star Strider
Star Strider on 31 Oct 2021
Use the exitflag output from fsolve to determine whether a solution was found.
.
  14 Comments
Deokjae Jeong
Deokjae Jeong on 31 Oct 2021
Oh.... It works. I am so thankful to you. I learned a lot.
Star Strider
Star Strider on 31 Oct 2021
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

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!