Effacer les filtres
Effacer les filtres

Columnwise operation.

8 vues (au cours des 30 derniers jours)
Andy McCann
Andy McCann le 15 Avr 2012
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

Réponses (1)

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

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by