フィルターのクリア

how to save all the loop values?

1 回表示 (過去 30 日間)
Rakesh R
Rakesh R 2019 年 3 月 11 日
回答済み: Star Strider 2019 年 3 月 11 日
for e = -1.5099
for f = (48000:49000)
e
f
h = ((((p*10^6)*x)/(12*i*((e*def)+f)))*(((3*(l^2))/4)-(x^2)));
if h==k
return;
end
end
end
  1 件のコメント
Rakesh R
Rakesh R 2019 年 3 月 11 日
the results generated gets over written and i end up with onel 1x1 result of h. But i want all the results of the iteration.

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

回答 (1 件)

Star Strider
Star Strider 2019 年 3 月 11 日
Try this:
fv = 48000:49000
e = -1.5099
for k1 = 1:numel(fv)
% e
% f
f = fv(k1);
h(k1) = ((((p*10^6)*x)/(12*i*((e*def)+f)))*(((3*(l^2))/4)-(x^2)));
if h==k
return;
end
end
Since ‘e’ is a scalar, there is no reason to loop over it. Also, your original code will create a 49000 element vector, only 1000 of which will be non-zero. This approach creates a 1000 element vector instead.
NOTE — This is UNTESTED CODE. I have no idea what your other variables are, so I cannot run this to test it.

カテゴリ

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