I don't receive the error message I'm supposed to

조회 수: 1 (최근 30일)
Kavin Kadam
Kavin Kadam 2020년 9월 20일
댓글: Walter Roberson 2020년 9월 20일
My textbook says "there must always be the same number of values in each row and each column of a matrix"
They give this as an example of proper code:
>>mat=[431;256]
mat=
4 3 1
2 5 6
And this as an example of improper code:
>>mat=[357;12]
It says I should be getting an error that says "dimensions of arrays being concatenated are not consistent", but I don't get this error, instead MATLAB registers the code as:
mat=
123
12
Does anyone know what goes on here? Thanks in advance!
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 9월 20일
Somehow you are missing spaces.
>> mat=[431;256]
mat =
431
256
>> mat=[4 3 1;2 5 6]
mat =
4 3 1
2 5 6

댓글을 달려면 로그인하십시오.

채택된 답변

Kavin Kadam
Kavin Kadam 2020년 9월 20일
It is because there is no space between 123 and 12, so it interprets it as 1 number.

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 9월 20일
That code is perfectly fine. Perhaps the bad code is
mat=[3,5,7;1,2] % Preferred - commas between
or
mat = [3 5 7; 1 2] % Not preferred - spaced between Might get orange warning squiggles.
In those cases there would be 3 columns in the first row and 2 columns in the second row, which is not allowed.

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by