I've got a wrong solution when I subtract two matrices with Incompatible Sizes between the row and column.
>> s = [-1 8 5]
s =
-1 8 5
>> t = [7;0;11]
t =
7
0
11
>> s-t
ans =
-8 1 -2
-1 8 5
-12 -3 -6
it should be the following answer:
??? Error using ==> - Matrix dimensions must agree.

4 comentarios

Birdman
Birdman el 27 de Feb. de 2018
Where is the following answer?
Abo Mohammed
Abo Mohammed el 27 de Feb. de 2018
Editada: Abo Mohammed el 27 de Feb. de 2018
it should be expect a following error:
??? Error using ==>- Matrix dimensions must agree.

Iniciar sesión para comentar.

 Respuesta aceptada

Torsten
Torsten el 27 de Feb. de 2018

0 votos

https://blogs.mathworks.com/loren/2016/10/24/matlab-arithmetic-expands-in-r2016b/
Without further comment on the usefulness of this feature.
Best wishes
Torsten.

Más respuestas (1)

KSSV
KSSV el 27 de Feb. de 2018
s = [-1 8 5] ;
t = [7;0;11] ;
if isequal(size(s),size(t))
iwant = s-t ;
else
error('using ==>- Matrix dimensions must agree.')
end

1 comentario

That prohibits scalar expansion as well. If you want to allow scalar s with non-scalar t or vice versa:
if isequal(size(s),size(t)) || isscalar(s) || isscalar(t)
iwant = s-t ;
else
error('using ==>- Matrix dimensions must agree.')
end

Iniciar sesión para comentar.

Categorías

Preguntada:

el 27 de Feb. de 2018

Comentada:

el 27 de Feb. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by