Indexing a value from a vector
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
I have a for loop where I need to index the vector element when the value exceeds 120, and display the number of iterations it took to reach that value. Can anyone help me? My code:
n=100;
p(1)=14.7;
for i=2:n-1
p(i)=((patm*v1+p(i-1)*vtire)/(v2+vtire));
end
pg=p-patm
and of course all these variable are defined earlier in the script
0 件のコメント
回答 (2 件)
Wayne King
2013 年 10 月 3 日
編集済み: Wayne King
2013 年 10 月 3 日
If you don't know the number of iterations in advance, why use a for loop?
Here, I'll test when any element of p goes negative and the looking at the length of the vector, you'll know it occured in the length-1.
n = 2;
p(1) = 14.7;
while all(p>0)
p(n) = p(n-1)-0.01;
n = n+1;
end
length(p)
3 件のコメント
Nick
2013 年 10 月 3 日
Wayne King
2013 年 10 月 3 日
Then what Azzi suggests should work
Nick
2013 年 10 月 3 日
Azzi Abdelmalek
2013 年 10 月 3 日
編集済み: Azzi Abdelmalek
2013 年 10 月 3 日
n=100;
p(1)=14.7;
for i=2:n-1
p(i)=((patm*v1+p(i-1)*vtire)/(v2+vtire));
end
pg=p-patm
idx=find(p>=120)
0 件のコメント
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!