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

1 Ansicht (letzte 30 Tage)
Kavin Kadam
Kavin Kadam am 20 Sep. 2020
Kommentiert: Walter Roberson am 20 Sep. 2020
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 Kommentar
Walter Roberson
Walter Roberson am 20 Sep. 2020
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Kavin Kadam
Kavin Kadam am 20 Sep. 2020
It is because there is no space between 123 and 12, so it interprets it as 1 number.

Weitere Antworten (1)

Image Analyst
Image Analyst am 20 Sep. 2020
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.

Kategorien

Mehr zu Numeric Types finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by