Borrar filtros
Borrar filtros

matrix multiplication in matlab

1 visualización (últimos 30 días)
vasantha malairamar
vasantha malairamar el 29 de Mzo. de 2017
Comentada: Jan el 29 de Mzo. de 2017
XYZ=[0.5141 0.3239 0.1604;0.2651 0.6702 0.0641;0.0241 0.1228 0.8444];
for i=1:768
for h=1:768
nf=mR(i,h);
fd=mG(i,h);
gs=mB(i,h);
bv=[nf fd gs];
hd=bv';
disp(hd);
mmul=double(hd).*XYZ;
disp(mmul);
end
end
Error using .* Matrix dimensions must agree.
Error in Untitled6 (line 22) mmul=double(hd).*XYZ;

Respuestas (1)

Jan
Jan el 29 de Mzo. de 2017
All we see is the failing code, and we have to guess its intention. Better explain this to get the solution you want.
double(hd) .* XYZ
[3 x 1] .* [3 x 3]
Do you want the result to be [3 x 3]? This works in Matlab >= 2016b with automatic expanding. With older versions, the elementwise multiplication demands for two arguments of the same size. Then:
mmul = bsxfun(@times, double(hd), XYZ);
or
mmul = double(hd(:, [1,1,1]) .* XYZ;
But perhaps you want a matrix multiplication?
mmul = double(bv) * XYZ;
  2 comentarios
Rik
Rik el 29 de Mzo. de 2017
Also: you should convert numbers to strings before using disp. You can use fprintf, a combination of sprintf and disp, or a combination of num2str and disp. I strongly advise the first.
Jan
Jan el 29 de Mzo. de 2017
@Rik: disp works well with numbers and arrays:
x = rand(2)
disp(x)

Iniciar sesión para comentar.

Categorías

Más información sobre Cell Arrays 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