Matrix dimensions must agree.

This function make a coordinates from sensor in another coordintes and scale from mm to m. but it gives me the following error message (Matrix dimensions must agree.) at line: Bix = Bix .* sign(MP).* 1000;
% code
MP = [P0(:,3), P0(:,4), P0(:,5)] ./ 1000;
Bix = [(interp3 (xs, ys, zs, Bxs, abs(MP(:,1)), abs(MP(:,2)), abs(MP(:,3))));...
(interp3 (xs, ys, zs, Bys, abs(MP(:,1)), abs(MP(:,2)), abs(MP(:,3))));...
(interp3 (xs, ys, zs, Bzs, abs(MP(:,1)), abs(MP(:,2)), abs(MP(:,3))))];
Bix = Bix .* sign(MP).* 1000;
Bix = Bix .* [1, -1, -1];

5 comentarios

José-Luis
José-Luis el 2 de Ag. de 2017
Have you tried using the debugger and looking at the size of the offending variables?
Are you trying to to implicit expansion for arithmetic operations and your Matlab < R2016b?
KSSV
KSSV el 2 de Ag. de 2017
Sizes of Bix and sign(MP) should be same.....They are not in your case.
José-Luis
José-Luis el 2 de Ag. de 2017
They don't need to be the same if OP is trying to do implicit expansion.
KSSV
KSSV el 2 de Ag. de 2017
@Jose-Luis..Run this
K = rand(1,10).*rand(1,5)
José-Luis
José-Luis el 2 de Ag. de 2017
Editada: José-Luis el 2 de Ag. de 2017
You're not getting my point, I think.
Arrays no longer need to have the same number of elements for such arithmetic operations to produce results.
Unsolicited disclaimer: I am having a hard time liking that. I'll eventually get on with the times.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 2 de Ag. de 2017
Use the debugger to identify the problem. Set a breakpoint in the failing line:
Bix = Bix .* sign(MP).* 1000;
Then run the code again until it stops. Not check the dimensions:
size(Bix)
size(MP)
For a proper elementwise multiplication, the dimensions must match. Do they?
Note that Matlab >= 2016b can auto-expand dimensions. With older versions, bsxfun helps. Perhaps you want:
Bix = bsxfun(@times, Bix, sign(MP)) * 1000;
Maybe a reshape helps here to adjust the dimensions as wanted.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 2 de Ag. de 2017

Respondida:

Jan
el 2 de Ag. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by