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)?
조회 수: 11 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Sandy Patel
2011년 1월 21일
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
subplot(3,1,1)
plot(xdata, y1data, 'Color', 'r');
subplot(3,1,2)
plot(xdata, y2data, 'Color', 'r');
% linkdata; % turn linkdata on here to connect plot 1 and plot 2 on figure 1,
subplot(3,1,3)
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
댓글 수: 0
추가 답변 (2개)
Peyman Obeidy
2016년 8월 3일
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
댓글 수: 0
Jahandar Jahanipour
2016년 10월 13일
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 ?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!