4.3) Creating Vectors And Matrices
- We can create vectors in Matlab by surrounding elements with [ ]. For example:
- A useful command to find out the size of any variables is "size", for example:
- Another useful command is "whos", which details current information on the variable:
[matlab]
>> a=[1 2 3 4 5 6 7 8 9 10];
[/matlab]
Generates a row vector named "a" which has size 1x10, where the elements have taken the values from 1 to 10
[matlab]
>> size(a)
ans=1 10
[/matlab]
Indicating a 1x10 row vector.
[matlab]
>> whos a
Name Size Bytes Class Attributes
a 1x10 80 double
[/matlab]
Here, bytes is the memory used by Matlab to store the variable (10 numbers of class double, each 8 bytes long). Class is the type of data, in this case "double". We will talk more about data classes later.