Is there any difference between [1 2] and [1, 2] in MATLAB?

>> [1 2]

ans =

     1     2

>> [1 ,2]

ans =

     1     2

>> 

      

Sounds like it's true?

+2


a source to share


3 answers


Nope; there is no difference. See here for more information:



The easiest way to create a matrix in MATLAB - use the matrix constructor operator []

. Create a row in the matrix by entering elements (shown as E

below) within the brackets. Separate each element with a comma or space:

row = [E1, E2, ..., Em]          row = [E1 E2 ... Em]

      

+8


a source


Both create a string vector when applied to scalar elements, i.e. horizontal concatenation. Space is equivalent to a comma within square brackets for constructing an array or vector. In fact, you can use whitespace and commas as you see fit in this expression, although this might be best done as it will confuse reading. For example, this is hard for me to read:

A = [1 2,3, 4 , 5 6 7, 8]

      

It is easier to read either one of these alternatives:



A = [1 2 3 4 5 6 7 8]
A = [1,2,3,4,5,6,7,8]

      

If you were to split the elements; instead it will result in vertical concatenation, which is a different animal. You can also create arrays using these delimiters. So, to create a 2x3 array,

A = [1 2 3;4 5 6]
A =
     1     2     3
     4     5     6

      

+4


a source


If you have doubts about the future, check out ISEQUAL :

>> a=[1 2];
>> b=[1,2];
>> isequal(a,b)
ans =
     1

      

0


a source







All Articles