Regarding matrix operation in MATLAB
    6 views (last 30 days)
  
       Show older comments
    
for i=1:5
s(i,:)=randi([0 1],1,5); 
xl=0;
xu=1860;
l=5;
si=bi2de(s);
b=(xl+((xu-xl)/((2^l)-1)))*si;
end
disp([s,si,b]);
I have a code like this. I want that if it generates s(i,:) all zero then it should terminate and start the whole process again. Please help me how can I do this.
0 Comments
Accepted Answer
  Guillaume
      
      
 on 23 Feb 2015
        restart = true;
while restart
   restart = false; %in case it succeeds
   for i = 1:5
      s(i, :) = ...
      if all(s(i, :) == 0)
         restart = true;
         break; %stop the for loop, thus restarting from scratch 
      end
      %...
   end
end
2 Comments
  Stephen23
      
      
 on 23 Feb 2015
				On the line
s(i, :) = ...
You actually need to put some code, just as you allocated values to s in your original code. Guillaume kindly showed you where to put this allocation, but they cannot write your code for you on your computer. This is up to you!
More Answers (0)
See Also
Categories
				Find more on Creating and Concatenating Matrices 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!
