Calculate values only once in the loop
    5 views (last 30 days)
  
       Show older comments
    
Suppose I have a code running in a loop I have done some operations and I create a matrix in the loop, that matrix has the same size in every iteration. How do i calculate the number of elemens of the matrix only for the first iteration and not for every iteration since i know that it will be the same for every iteration? I want to avoid using ifelse statements.
0 Comments
Answers (2)
  Amir Xz
      
 on 12 Sep 2018
        Use "isempty":
I = rand(4,5);r=[]; c=[];
for i=1:10    
  if isempty(r) || isempty(c)
      [r,c]=size(I);
  end
end
0 Comments
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!


