How to interactively select different plots in a figure and merge them together?
Show older comments
I have several little lines of plot that represent portions of particle trajectories: each of such "pieces" are described by x- and y-coordinates. I am looking for a way to produce a figure of all these pieces, click on each of the pieces that visually belong to the same trajectory, and merge their x- and y- coordinates into a single array.
Here is a very simple example:
x = linspace(0,pi,100);
y = sin(x); z = cos(x/2);
x1 = x(1:12); y1 = y(1:12);
x2 = x(19:25); y2 = y(19:25);
x3 = x(45:67); y3 = y(45:67);
x4 = x(90:end); y4 = y(90:end);
x5 = x(4:19); y5 = z(4:19);
x6 = x(40:88); y6 = z(40:88);
plot(x1,y1,'b'); grid on; hold on
plot(x2,y2,'b')
plot(x3,y3,'b')
plot(x4,y4,'b')
plot(x5,y5,'r')
plot(x6,y6,'r')
From here, I need to click on all the blue plots (which belong to the "sine" trajectory) or red plots (which belong to the "cosine" trajectory), collect their coordinates and save them into a single array (for a future reconstruction of the original trajectory or whatever).
Searching a bit through MATLAB Answers, I came across this question that explains how to extract data from MATLAB figures. This is quite similar to what I need; but instead of by inspecting properties, I need to do it interactively by clicking on each plot, one after the other, and saving in the workspace the XData and YData of all plots I have clicked. In this sense, the concept should be similar to what ginput does with plot coordinates.
Accepted Answer
More Answers (0)
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!