フィルターのクリア

MatLab for loop question

2 ビュー (過去 30 日間)
Todd
Todd 2013 年 11 月 9 日
コメント済み: Walter Roberson 2013 年 11 月 9 日
Hey guys, probably a simple question but I'm new at this and pretty confused.
So I'm trying to raise a matrix to the powers of 1,2,3,4,5,10,20,25,50,and 75, so I wrote
for t={1,2,3,4,5,10,20,25,50,75}
(A^t)
end
But this is only raising the matrix to the 75th, how do I do this?

採用された回答

Walter Roberson
Walter Roberson 2013 年 11 月 9 日
That code will error out when it first tries to raise the matrix to a power. When you give a cell array of values as the list of values for a "for" loop, the loop variable is set to a cell containing each element in the list, so you would be trying to first raise A to {1} rather than to 1.
If you had used [] instead of {}. the code shown would raise to each power and display the result, but would not do anything with the results other than to display them.
Perhaps your code looks different than what you posted?
  2 件のコメント
Todd
Todd 2013 年 11 月 9 日
編集済み: Todd 2013 年 11 月 9 日
Thank you! Took out the commas and replaced the {} with [] and it worked!
Walter Roberson
Walter Roberson 2013 年 11 月 9 日
For future reference: you could have left in the commas.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by