필터 지우기
필터 지우기

Columnwise operation.

조회 수: 9 (최근 30일)
Andy McCann
Andy McCann 2012년 4월 15일
I was hoping someone could help me with quite a basic problem, i just think i've been looking at it too long to notice what i've been doing wrong.
I have P by T matrix, where P and T are the length of vectors containing different values of theta and phi. So every matrix element represents a position in theta and phi.
I want to multiply every element in a matrix by the sin of the angle of the column it is in. Eg, multiply all elements in the first column by sin(theta(1)) and elements in 2nd column by sin(theta(2)) and so on.
Here is what i have so far but it really isnt running correctly.
Can anyone help?
function Volume = Volume(theta, phi)
R_Drop = 2e-6.*rand(45,45);
R_SQ = R_Drop.*R_Drop;
R_SQ_s = zeros(size(R_SQ));
for Th = 1:length(theta)
%%This is the line that is wrong, below.
R_SQ_s(:,Th) = (R_SQ(:,Th)).*sin(theta(Th));
end
Volume = trapz(trapz((R_SQ_s)'));
Thanks a lot

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 4월 15일
R_SQ_s = ones(size(R_SQ),1)*sin(theta(:).').*R_SQ;
or
R_SQ_s = bsxfun(@times,R_SQ,sin(theta(:).'));

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by