How to check every single element in a vector

37 ビュー (過去 30 日間)
Abdul A
Abdul A 2017 年 2 月 23 日
編集済み: Abdul A 2017 年 2 月 27 日
Hello everyone, I have a question about Matlab. I have a vector A=[ 1 1.2 1.3 1.4] and I need to create a loop to check every single element. Here is what I am trying to do:
for i= 1:100
whatever equations or process that gave me A=[ 1 1.2 1.3 1.4]
if A>=0.5
%(I want to check every single element not just a particular one. if not, I want Matlab to calculate a new value for A and check it again and again until they all less than 0.5. we started from i=1 in the first iteration. if the condition is not fulfilled take i=2, calculate a new A, and check again)
else
break
end
end
where A is printed vertically A=A(:)
Thank you

採用された回答

Abdul A
Abdul A 2017 年 2 月 27 日
編集済み: Abdul A 2017 年 2 月 27 日
Thank you for your prompt response.
What about:
for i=1:100
A=[? ? ? ?]
if any (A>=0.5)
else
break
end
end

その他の回答 (1 件)

Beder
Beder 2017 年 2 月 23 日
B=zeros(size(A));
B(A>=0.5)=1;
while sum(B)>0
for i=1:size(B)
if B(i)==1
A(i)=YOURFUNCTION
end
end
B=zeros(size(A));
B(A>=0.5)=1;
end
not tested. But maybe a hint how to do it. There will be for sure more advanced solutions out there :)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by