GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Wednesday, December 22, 2010

Vector In Matlab

In Matlab, data structure vector and matrix:
>> id = [4 5 6 2 4]
4 5 6 2 4
>> id = 1:5    % start:end
1 2 3 4 5
>> id = 1:2:10    % start:step:end
1 3 5 7 9

How to access elements in matrix:
>> id = [4 5 6 7 8]
4 5 6 7 8
>> id(1)    % Get the 1st element of the id
4
>> id([1 2 3])    % Get the 1st, 2nd, 3rd elements of id
4 5 6
>> id(1:3)    % Get the 1st till the 3rd elements
4 5 6
>> id(end)    % Get the last element
8
          
Share/Bookmark

No comments:

Post a Comment