>> A={1 2;2 3}
A =
[1] [2]
[2] [3]
>> A=[1 2;2 3]
A =
1 2
2 3
It seems to me they are essentially the same thing?
>> A={1 2;2 3}
A =
[1] [2]
[2] [3]
>> A=[1 2;2 3]
A =
1 2
2 3
It seems to me they are essentially the same thing?
No. They are not at all the same thing. The only aspect that is the same is the resulting shape.
An array (that which you build with []) is something you can use to do linear algebra. One number in each element.
A = [1 2 3;4 5 6;7 8 9];
[3 5 7]*A*[2 3 5]'
ans =
915
A cell array is a general container, that will hold any object, any matlab variable entirely in each cell. Thus we can create a cell array composed of elements of any shape and size.
C = {'The' 'quick' 'brown' 'fox' 'jumps' 'over' 'the' 'lazy' 'dog'};
C is a cell array with 9 elements in it. We can put any class of variable in there.
C = {'asfghhrstyjtysj', 1:5, magic(4), sqrt(-1)}
C =
'asfghhrstyjtysj' [1x5 double] [4x4 double] [0 + 1i]
We could even create a cell array where each cell contains only a single scalar number. But there would be no real point in doing so, as we cannot do arithmetic operations using cell arrays.
[]
is an array-related operator. An array can be of any type - array of numbers, char array (string), struct array or cell array. All elements in an array must be of the same type!
Example: [1,2,3,4]
{}
is a type. Imagine you want to put items of different type into an array - a number and a string. This is possible with a trick - first put each item into a container {}
and then make an array with these containers - cell array.
Example: [{1},{'Hallo'}]
with shorthand notation {1, 'Hallo'}
It is unnecessary to put objects of the same type (doubles) into a cell array like in your example.