matching matrices that correspond to each other in a graph

1 次查看(过去 30 天)
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.

采纳的回答

Alan Stevens
Alan Stevens 2021-1-29
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 个评论
Alan Stevens
Alan Stevens 2021-1-29
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by