I don't receive the error message I'm supposed to
1 view (last 30 days)
Show older comments
Kavin Kadam
on 20 Sep 2020
Commented: Walter Roberson
on 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 Comment
Walter Roberson
on 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
Accepted Answer
More Answers (1)
Image Analyst
on 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.
0 Comments
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!