Borrar filtros
Borrar filtros

How do I join 3D scatter points/markers together with lines to create different 'segments'?

4 visualizaciones (últimos 30 días)
I'm trying to create a model using static data points, but I want to join some of these points together with a line to create segments so I can clearly identify where each segment starts and stops. Does anyone know how I can do this?
Here is an example of my code:
scatter3(RT0(1,1), RT0(1,2), RT0(1,3), 'fill', 'g') %Segment 1
scatter3(RT1(1,1), RT1(1,2), RT1(1,3), 'fill', 'g')
scatter3(RT2(1,1), RT2(1,2), RT2(1,3), 'fill', 'g')
scatter3(RT3(1,1), RT3(1,2), RT3(1,3), 'fill', 'g')
scatter3(LT0(1,1), LT0(1,2), LT0(1,3), 'fill', 'g')
scatter3(LT1(1,1), LT1(1,2), LT1(1,3), 'fill', 'g')
scatter3(LT2(1,1), LT2(1,2), LT2(1,3), 'fill', 'g')
scatter3(LT3(1,1), LT3(1,2), LT3(1,3), 'fill', 'g') % end of 'seg1' - I want to create lines to join all points in green
scatter3(LLK(1,1), LLK(1,2), LLK(1,3), 'fill', 'b')
scatter3(LMK(1,1), LMK(1,2), LMK(1,3), 'fill', 'b')
scatter3(RLK(1,1), RLK(1,2), RLK(1,3), 'fill', 'b')
scatter3(RMK(1,1), RMK(1,2), RMK(1,3), 'fill', 'b') % I want to be able to join the blue points together so they form a seperate 'segment'
scatter3(RS0(1,1), RS0(1,2), RS0(1,3), 'fill', 'y')
scatter3(RS1(1,1), RS1(1,2), RS1(1,3), 'fill', 'y')
scatter3(RS2(1,1), RS2(1,2), RS2(1,3), 'fill', 'y')
scatter3(RS3(1,1), RS3(1,2), RS3(1,3), 'fill', 'y')
scatter3(LS0(1,1), LS0(1,2), LS0(1,3), 'fill', 'y')
scatter3(LS1(1,1), LS1(1,2), LS1(1,3), 'fill', 'y')
scatter3(LS2(1,1), LS2(1,2), LS2(1,3), 'fill', 'y')
scatter3(LS3(1,1), LS3(1,2), LS3(1,3), 'fill', 'y') % join yellow points together
I've tried using plot or plot3 instead of scatter3 graphs, but it doesn't work for what I want to do. please bear in mind I will be needing to input a for loop to view different configurations.
I hope what I'm asking makes sense? Any help would be much appreciated!
Thank you in advance!
  4 comentarios
KSSV
KSSV el 24 de Jun. de 2020
Make all the x, y, z points of first set into a single array each...and then use plot3.
MADRobot
MADRobot el 25 de Jun. de 2020
Thanks for your help. I've accepted Benjamin's answer as the example he showed an example which helped me understand how to do it

Iniciar sesión para comentar.

Respuesta aceptada

Voss
Voss el 24 de Jun. de 2020
It looks like each of your lines contains only one point. Maybe try something like this:
plot3( ...
[RT0(1,1) RT1(1,1) RT2(1,1) RT3(1,1)], ...
[RT0(1,2) RT1(1,2) RT2(1,2) RT3(1,2)], ...
[RT0(1,3) RT1(1,3) RT2(1,3) RT3(1,3)], ...
'-o');
% etc ...
This'll give you a line with four points.
  5 comentarios
Voss
Voss el 25 de Jun. de 2020
One way would be to call plot3 with each pair of points:
plot3([RT0(1,1) RT1(1,1)],[RT0(1,2) RT1(1,2)],[RT0(1,3) RT1(1,3)],'-o'); % RT0 is connected to RT1
plot3([RT0(1,1) RT2(1,1)],[RT0(1,2) RT2(1,2)],[RT0(1,3) RT2(1,3)],'-o'); % RT0 is connected to RT2
plot3([RT0(1,1) RT3(1,1)],[RT0(1,2) RT3(1,2)],[RT0(1,3) RT3(1,3)],'-o'); % RT0 is connected to RT3
plot3([RT1(1,1) RT2(1,1)],[RT1(1,2) RT2(1,2)],[RT1(1,3) RT2(1,3)],'-o'); % RT1 is connected to RT2
plot3([RT1(1,1) RT3(1,1)],[RT1(1,2) RT3(1,2)],[RT1(1,3) RT3(1,3)],'-o'); % RT1 is connected to RT3
plot3([RT2(1,1) RT3(1,1)],[RT2(1,2) RT3(1,2)],[RT2(1,3) RT3(1,3)],'-o'); % RT2 is connected to RT3
Another way would be to combine the RT* variables into a single variable and index into that variable:
RT = [RT0(1,:); RT1(1,:); RT2(1,:); RT3(1,:)]; % taking the first row of each RT* and putting them in a matrix RT
idx = [1 2 3 1 4 2 3 4]; % the order the points will be plotted, such that each one
% is adjacent to each other one in the list at least once
% (this would need to be modified if you want to do this with
% some number of points other than 4)
plot3(RT(idx,1),RT(idx,2),RT(idx,3),'-o');
In fact I recommend combining RT0,...,RT3 into a single variable in general (and the same for LS0,...,LS3 and any other sets of variables you have), not only for plotting, but for any calculations you need to do as well. You can see already that this second approach is a lot simpler, and easier to read, etc. Have a look around this thread for details:
MADRobot
MADRobot el 25 de Jun. de 2020
ahhh thank you so much! I just tested it using a different number of points and I managed to get it working. Thank you so much! You're a life saver!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by