필터 지우기
필터 지우기

Regarding matrix operation in MATLAB

조회 수: 1 (최근 30일)
Abhinav
Abhinav 2015년 2월 23일
댓글: Stephen23 2015년 2월 23일
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.

채택된 답변

Guillaume
Guillaume 2015년 2월 23일
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
Abhinav
Abhinav 2015년 2월 23일
Not working. Showing illegal use of reserved keyword IF
Stephen23
Stephen23 2015년 2월 23일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by