필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by