MATLAB: Matching matrices that correspond to each other in a graph

plot graph different colour specific points

I would like to plot a graph with matrices that correspond to each other.
For example,
correspond = [0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0]; %logical matrix
X = [13 14 51 31 32 45 25 63 25 43 89 34 38 48 37 29 34 12 46 27 21]; %x axis values
red = [0 0 0 0 3 0 0 0 0 6 0 0 0 0 0 0 8 0 0 0 0]; %these points correspond to '1' in the
% logical matrix above, i want to colour them brown.
green = [4 2 4 5 2 9 8 7 3 8 1 2 3 1 4 6 3 8 4 1 2]; %I want to remove the numbers in this matrix
% that corresponds to '1' in the logical matrix above, and then colour these points yellow.
So the final matrix Y should look something like this after merging both 'red' and 'green' matrices.
Y = [4 2 4 5 3 9 8 7 3 6 1 2 3 1 4 6 8 8 4 1 2]; %points in the 5th, 10th and 17th positions
% been replaced.
plot(X,Y) %with the respective colours for the different points.

Best Answer

Do you mean something like this (I'll leave you to play with the colours):
correspond = [0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0]; %logical matrix
X = [13 14 51 31 32 45 25 63 25 43 89 34 38 48 37 29 34 12 46 27 21]; %x axis values
id = find(correspond==1);
xred = X(id);
red = [0 0 0 0 3 0 0 0 0 6 0 0 0 0 0 0 8 0 0 0 0]; %these points correspond to '1' in the
red(red==0)=[];
% logical matrix above, i want to colour them brown.
green = [4 2 4 5 2 9 8 7 3 8 1 2 3 1 4 6 3 8 4 1 2]; %I want to remove the numbers in this matrix
green(id) = NaN;
plot(X,green,'go',xred,red,'ro'),grid
Y = green;
Y(isnan(green)) = red;
disp(Y)