MATLAB Answers

0

Why can't i input matrices other than square matrix in MATLAB 16B and 17A??

Asked by Shivam Upadhyaya on 8 Apr 2017
Latest activity Commented on by Stephen Cobeldick on 8 Apr 2017
Like when i input A=[1,2,3;4,5] MATLAB is not assigning this to variable A

  1 Comment

The name MATLAB stands for MATrix LABoratory, and by the standard mathematical definition matrices must have an element in every location, i.e. not contain any holes. The shape you are trying to define contains holes, i.e. not all elements are defined. Ergo it is not a matrix, and will throw an error. This is the expected and correct behavior.

Sign in to comment.

1 Answer

Answer by Star Strider
on 8 Apr 2017

You have 3 elements in ‘A(1,:)’ and 2 in ‘A(2,:)’. That is not permitted in double arrays.
Empty elements in cell arrays are allowed:
A = {1,2,3; 4,5,[]};
However, calculating with such arrays as double arrays remain as not permitted. Fill the ‘empty’ element with NaN if you must, although it will likely result in NaN results of calculations with that matrix.

  0 Comments

Sign in to comment.