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 Center および File ExchangeNumeric Types についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by