question of for loop

2 ビュー (過去 30 日間)
mahesh chathuranga
mahesh chathuranga 2013 年 9 月 7 日
for i=1:10 power=(i*i) end; this is my programme and ,now i want to calculate all the values of power.
  1 件のコメント
mahesh chathuranga
mahesh chathuranga 2013 年 9 月 10 日
thak you very much.i'm very new for MATLAB

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

採用された回答

Image Analyst
Image Analyst 2013 年 9 月 7 日
Do you have a question, other than "How do I format my code?" which is answered by this. Might it be "How do I get power to be an array?" If so, just make * a .* and drop the "for" and "end".
k = 1 : 10; % No "for" needed since it's now vectorized.
power = k .* k % or can use power = k .^2

その他の回答 (0 件)

カテゴリ

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