Info

此问题已关闭。 请重新打开它进行编辑或回答。

while loop/breaking a loop

1 次查看(过去 30 天)
Rengin
Rengin 2015-4-22
关闭: MATLAB Answer Bot 2021-8-20
Dear Users,
clear all
clc
nparticle=15;
nclass=3;
maxlimit=10;
minlimit=50;
value=zeros(nparticle,nclass);
for i=1:nparticle
for j=1:nclass
value(i,j)= round(minlimit + (maxlimit-minlimit).* rand (1));
end
end
% In that part, I want to check the cells in a row one by one and if one
% cell doesn't meet the requirement what I put,I want to go back the
% beginning of the main loop and go on generating random values.
% My condition: if value(i,j)>25--> assign new random values for ith
% particle!
% Let's say value(4,1)=12 value(4,2)=28 value(4,3)=10
% 4-->4th particle
% 2-->2nd class
% It means my 4th particle doesn't meet the requirement (>25) independent
% from nclass/column/j.
% In that case, I want to assign 4th particle with new random values till I
% meet the requirements for 4th particle. I want to continue the process
% till I fulfill all rows of value(nparticle,nclass) matrix.
How can I solve that problem? Many thanks!

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by