MATLAB Answers

how to write a very concise expression for matrix power

조회 수: 5(최근 30일)
Xin
Xin 12 Oct 2016
Commented: dpb 12 Oct 2016
I have a row vector, e.g. [1,2,3,4], and I want to put, say 3 different power [1;2;3] to create a matrix as follow:
[1,2,3,4]?^[1;2;3] = [1,2,3,4 ; 1,4,9,16 ; 1,8,27,64].
Anyone knows how to get it without using a loop. Many thanks!

  댓글 수: 0

로그인 to comment.

채택된 답변

Matt J
Matt J 12 Oct 2016
As of R2016b, you can just do this
[1;2;3] .^ [1,2,3,4]
Otherwise, use bsxfun()

  댓글 수: 4

표시 이전 댓글 수: 1
Matt J
Matt J 12 Oct 2016
Upgrade!
Or, use bsxfun() as I suggested.
Xin
Xin 12 Oct 2016
Nice, bsxfun does work. Thank you so much!
dpb
dpb 12 Oct 2016
Then please ACCEPT the answer...

로그인 to comment.

More Answers (1)

dpb
dpb 12 Oct 2016
>> bsxfun(@power,[1:4],[1:3].')
ans =
1 2 3 4
1 4 9 16
1 8 27 64
>>

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그


Translated by