matching matrices that correspond to each other in a graph
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Leon Low
el 29 de En. de 2021
Comentada: Leon Low
el 29 de En. de 2021
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.
0 comentarios
Respuesta aceptada
Alan Stevens
el 29 de En. de 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 comentarios
Alan Stevens
el 29 de En. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!