matching matrices that correspond to each other in a graph

4 ビュー (過去 30 日間)
Leon Low
Leon Low 2021 年 1 月 29 日
コメント済み: Leon Low 2021 年 1 月 29 日
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.
Leon Low
Leon Low 2021 年 1 月 29 日
oh okay thank you! it works great!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by