MATLAB: Intro to programing MATLAB, Matrix

MATLABmatrix indexing

Hello everyone I just finished a assignment and was wondering if there was a easier answer then i got the question was
Given matrix A assign the second column to a variable v. after change elements of last row to 0
A=[1:5; 6:10; 11:15; 16:20];
i used
v = A(1:4,2)
A= [1:5; 6:10; 11:15; 0,0,0,0,0]]
the answer is correct but how could i have made it simpler? Recomendations?

Best Answer

You can use the colon to index all values in a dimension:
IMG(2,2,:)=[100 255 255];%assign RGB values to a pixel
You can also use the end keyword to index into the last element of a dimension:
Blue=IMG(:,:,end);
I'm not giving more specific instructions, because that would encourage you to cheat.