how to use two while and for loops?

hi to all:
i have two condition in my problem in matlab.
(1) matlab should run the first statement when x<1 .
(2) when x reaches to x>1 or x=1 the matlab should run the second statement.
thanks from all of you

回答 (1 件)

KSSV
KSSV 2021 年 3 月 7 日

0 投票

if x < 1
statement1
elseif x >= 1
statement2
end

6 件のコメント

Engineer Batoor khan mummand
Engineer Batoor khan mummand 2021 年 3 月 7 日
Respected sir thanks from your reply but x is not single value it is matrix.
Engineer Batoor khan mummand
Engineer Batoor khan mummand 2021 年 3 月 7 日
編集済み: Engineer Batoor khan mummand 2021 年 3 月 7 日
Let me explain it to you I have four rows which I called it x if one row reaches to one or greater than one than it should go to row two and follow the same procedure till last row. Thanks
KSSV
KSSV 2021 年 3 月 7 日
[m,n] = size(x) ;
for i = 1:m
for j = 1:n
if x(i,j) < 1
statement1
elseif x(i,j) >= 1
statement2
end
end
end
Engineer Batoor khan mummand
Engineer Batoor khan mummand 2021 年 3 月 7 日
thanks you so much respected sir
this is that part of my programming which i have proble.
while m(i)<1
i=1:n-1
itn=itn+1
Rhn(1:n,i) = ((pi*rh(1:n,i).^4)/8*nuD*L).*(m(i)+(1-m(i))*M);
qhn(1:n,i)=qh(1:n,i).*Rh(1:n,i)./Rhn(1:n,i);
Vh(1:n,i) = (qhn(1:n,i))./Ah(1:n,i)
if m(i)<=0.5
delXmax = 0.1
else
delXmax = 0.07
end
deltat=min(min(delXmax./Vh))
m(i)= m(i)+Vh(1:n,i)*deltat;
end
end
i want that m should strat from 0 and run in first row or column when it reaches to 1>= 1 , than it should move to second row or column and foloow same initail condition (m>=1). once again thank you so much
Engineer Batoor khan mummand
Engineer Batoor khan mummand 2021 年 3 月 7 日
i is the number of rows respected sir first i wan to do it for rows than for columns .
where i=1
it should follow the rule i+1 when m>=1.
thanks
Engineer Batoor khan mummand
Engineer Batoor khan mummand 2021 年 3 月 7 日
as you know in my programming the loop will stop when m reaches to 1 or greather 1, but i want it should go for i=2 and than i=3 and so on

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSimulink についてさらに検索

製品

リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by