Columnwise operation.
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
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(:).'));
0 commentaires
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!