I've got a wrong answer on subtract Matrices
이전 댓글 표시
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
Birdman
2018년 2월 27일
Where is the following answer?
Abo Mohammed
2018년 2월 27일
편집: Abo Mohammed
2018년 2월 27일
KL
2018년 2월 27일
You may want to read about implicit expansion.
KL
2018년 2월 27일
Another thread on this issue:
채택된 답변
추가 답변 (1개)
KSSV
2018년 2월 27일
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
Steven Lord
2018년 2월 27일
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
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!