Borrar filtros
Borrar filtros

Columnwise operation.

8 visualizaciones (últimos 30 días)
Andy McCann
Andy McCann el 15 de Abr. de 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

Respuestas (1)

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

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by