Azzera filtri
Azzera filtri

Regarding matrix operation in MATLAB

1 visualizzazione (ultimi 30 giorni)
Abhinav
Abhinav il 23 Feb 2015
Commentato: Stephen23 il 23 Feb 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.

Risposta accettata

Guillaume
Guillaume il 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 Commenti
Abhinav
Abhinav il 23 Feb 2015
Not working. Showing illegal use of reserved keyword IF
Stephen23
Stephen23 il 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!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by