フィルターのクリア

Columnwise operation.

8 ビュー (過去 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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by