matching matrices that correspond to each other in a graph

4 views (last 30 days)
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.

Accepted Answer

Alan Stevens
Alan Stevens on 29 Jan 2021
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)
  3 Comments
Alan Stevens
Alan Stevens on 29 Jan 2021
It means the elements of red that are equal to zero get set to an empty vector . i.e. they get removed, leaving red to be only the non-zero elements.

Sign in to comment.

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!