Regarding matrix operation in MATLAB
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!