How can I plot segments in a scatter plot?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi guys, I have a problem I hope you can help me to solve.
I have the following scatter plot:
I obtained it using the elements of line 7 (X vector) and line 9 (Y vector) of the following matrix:
Looking at lines 1,2,3, columns represent all the possibile combinations of 3 variables, A,B,C, which can assume values: A -> 0,1 B -> -1,0,1 C -> 0,1
through a given matrix expression which depends on A,B,C, it's possible to obtain 12 vectors stored in lines 4-6 of MM matrix.
through a three-phase two-phase transformation I finally obtained 12 vectors stored in lines 7-8 (2 components).
Now I'll explain my problem. I have to connect points in my plot following this rule: the corresponding vectors in lines 1-3 of MM matrix must have 2 coincident components and the difference between the different components must be +1 or -1
for example, considering points in columns 3 and 4, they have to be connected because the first and the second components are equal, the difference between third components is 1.
Hoping you understand what I'm trying to say, I'm sorry for my bad english. Thanks!
PS: I allegate my script
0 comentarios
Respuestas (1)
Mukul Rao
el 4 de Dic. de 2017
Hi, very interesting question. If my understanding is correct, I believe you should be looking at different possible combinations of the 12 unique vectors in the MM matrix, selected 2 at a time and then look at their components to determine if they satisfy the criteria for plotting.
Here is an example code snippet. It might not be entirely accurate, but could be a good starting point. I have also attached the plot that I obtain after adding this code snippet to your script.
%Get all combinations of the twelve vectors taken 2 at a time
vectorCombinations = nchoosek(1:12,2);
%Toggle the hold property so we can add the segment plots
hold(gca,'on');
%Loop through different combinations and for each combination, identify if
%the selected vectors satisfy the conditions for plotting
for i = 1:size(vectorCombinations,1)
index1 = vectorCombinations(i,1);
index2 = vectorCombinations(i,2);
vec1 = MM(1:3,index1);
vec2 = MM(1:3,index2);
if ( nnz(vec1 == vec2) ) %Do two components match?
diffIndex = vec1 ~= vec2;
if ( abs(vec1(diffIndex) - vec2(diffIndex) ) == 1 )
%Do the different components different by absolute value of 1?
% If yes then join the points corresponding to the choice
% indices
plot([X(index1);X(index2)],[Y(index1);Y(index2)],'Color','r');
end
end
end
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!