Effacer les filtres
Effacer les filtres

Regarding matrix operation in MATLAB

1 vue (au cours des 30 derniers jours)
Abhinav
Abhinav le 23 Fév 2015
Commenté : Stephen23 le 23 Fév 2015
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.

Réponse acceptée

Guillaume
Guillaume le 23 Fév 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 commentaires
Abhinav
Abhinav le 23 Fév 2015
Not working. Showing illegal use of reserved keyword IF
Stephen23
Stephen23 le 23 Fév 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!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by