Filter löschen
Filter löschen

Regarding matrix operation in MATLAB

1 Ansicht (letzte 30 Tage)
Abhinav
Abhinav am 23 Feb. 2015
Kommentiert: Stephen23 am 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.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by