Saving existing matrix
1 view (last 30 days)
Show older comments
Hi,
I would like to find a way to tell my code that if at the end of the loop the matrix 'P' exists then to save it, if not to continue the loop. I wrote that:
z=exist('P','var')
if z>0
save
end
It is wroking but, is it a good way to write it?
Cheers
0 Comments
Accepted Answer
Matt Fig
on 19 Apr 2011
Why would P exist sometimes and not others? If it is created somewhere in the loop, presumably an IF statement or other such branch, why not just save it there? Since your saved variable will be overwritten each time through the loop (that P exists), why not save after the loop?
More Answers (0)
See Also
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!