Exponentiation of Matrix Columns by different Powers

조회 수: 8 (최근 30일)
John
John 2015년 7월 6일
답변: James Tursa 2015년 7월 6일
Given an MxN matrix A and a 1xN vector b, is there a concise way to raise each column of A to a corresponding power of the vector b? For example, if N = 4, the resulting matrix C would be computed as:
C = [A(:,1)^b(1) A(:,2)^b(2) A(:,3)^b(3) A(:,4)^b(4)];
However, when N becomes large, explicitly writing this formula is not feasible. Is there a way to write this without the use of a loop? Thank you for any feedback.

채택된 답변

Brendan Hamm
Brendan Hamm 2015년 7월 6일
repmat can be used to create a matrix bExp of the same size as A where the rows are repeated.
bExp = repmat(b,size(A,1),1); % Expand b to be the size of A (assuming width are same)
C = A.^bExp;

추가 답변 (1개)

James Tursa
James Tursa 2015년 7월 6일
C = bsxfun(@power,A,b);

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by