Monday, 1 August 2016

MATLAB Programming 44 - Colon Notation (Example)


Example


Create a script file and type the following code in it:


A = [1 2 3 4; 4 5 6 7; 7 8 9 10]
A(:,2) % second column of A
A(:,2:3) % second and third column of A
A(2:3,2:3) % second and third rows and second and third columns

When you run the file, it displays the following result:


A =
1 2 3 4
4 5 6 7
7 8 9 10

ans =
2
5
8

ans =
2 3
5 6
8 9

ans =
5 6
8 9

No comments:

Post a Comment