>> [1 2]
ans =
1 2
>> [1 ,2]
ans =
1 2
>>
It looks the same,is that true?
>> [1 2]
ans =
1 2
>> [1 ,2]
ans =
1 2
>>
It looks the same,is that true?
Nope; there's no difference. See here for more info:
The simplest way to create a matrix in MATLAB is to use the matrix constructor operator,
[]
. Create a row in the matrix by entering elements (shown asE
below) within the brackets. Separate each element with a comma or space:row = [E1, E2, ..., Em] row = [E1 E2 ... Em]
Both produce a row vector when applied to scalar elements, i.e., horizontal concatenation. A space is equivalent to a comma inside square brackets to construct an array or vector. In fact, you can use spaces and commas at will within such an expression, although this may be best not done as it will be confusing to read. For example, this is difficult for me to read:
A = [1 2,3, 4 , 5 6 7, 8]
Far easier to read is either one of these alternatives:
A = [1 2 3 4 5 6 7 8]
A = [1,2,3,4,5,6,7,8]
Had you separated the elements with ; instead, this would produce vertical concatenation, which is a different animal. You can also build up arrays using these separators. So to create a 2x3 array,
A = [1 2 3;4 5 6]
A =
1 2 3
4 5 6