Effacer les filtres
Effacer les filtres

If I have two plots on the same figure window, how do I use the Brush tool to highlight one data point and have the corresponding data point on the other plot highlighted in MATLAB 7.11 (R2010b)?

12 vues (au cours des 30 derniers jours)
I have two plots side-by-side and they plot data with the same size. I would like to use the Brush tool to highlight one data point on one figure and have the corresponding data point on the second plot highlighted automatically.

Réponse acceptée

Sandy Patel
Sandy Patel le 21 Jan 2011
If you are using the Matlab figure toolbar then you can just select the 'Link' button before selecting the 'Brush' button and it should tie all the plots together with common data (doc linkdata for more). If you are coding it then, again, the key to this is using the 'linkdata' function in Matlab. Here is an example:
% ----- Begin Example: Linked Brushing
% create a figure
fig1 = figure();
% make some fake data
n =100;
xdata = 1:n;
y1data = rand(1,n);
y2data = rand(1,n)*2;
y3data = rand(1,n)*3;
% plot data
plot(xdata, y1data, 'Color', 'r');
plot(xdata, y2data, 'Color', 'r');
% linkdata; % turn linkdata on here to connect plot 1 and plot 2 on figure 1,
plot(xdata, y3data, 'Color', 'b');
linkdata; % turn linkdata on here to connect all plots on figure 1,
brush g; % change brush color for fun
brush on; % turn brushing on (or select it from the toolbar)
% ----- End Example: Linked Brushing
Now when you downclick, drag, and release over a section of data in one plot, it should brush the corresponding data in all plots.
I am not completely satisfied with this solution because I have not come up with a clean way to clear all brushed data across all plots (not remove the data, but just remove the brushed highlighting effect). It will always update the newly brushed data across all plots, but the only way to clear all the brushed data on all plots is to click on a blank area on the plot where you initially selected the brushed data. There should be a way to clear them all. If you are dealing with just 2 plots, you should be fine, but if there are say ten or more, clearing would be a pain. I know this is a little confusing, sorry. Just play with trying to clear the brushing in the example and it will become clear.
One other benefit of the code over the button is that if you were to move the linkdata call to just after the second plot call (and before the third subplot call) this would only tie the first 2 plots together and leave the third independent but still in brush mode.
Let me know if you have any questions. Sandy

Plus de réponses (2)

Peyman Obeidy
Peyman Obeidy le 3 Août 2016
This is very useful, thank you. I have two questions. let`s say that there is a table with 3 rows and 5 columns and we only used 4 columns to plot the data. a) how do you extract the linked data (e.g. if we plotted 4 column, how can we have the outcome to be a 3x4 table)? b) is it possible to extract the fifth corresponding value too?
Best regards Peyman

Jahandar Jahanipour
Jahandar Jahanipour le 13 Oct 2016
If we have a matrix with 4 columns which we plotted first two columns with one figure and last two columns with another figure; how can we link the data in this case ?


En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by