1

I have plotted multiple subplots in a same figure. When I move the cursor above the plot, I wanted to read the values from each subplot instead of inserting ‘Datapoint’ manually at each subplots.

A=[1 2 3 4 5 6];
B=[3 4 5 6 2 8];
C=[3 2 7 5 8 3];
figure(1);
subplot(2,1,1);
plot(A,B,'m')
hold on;
subplot(2,1,2);
plot(A,C,':y')
Title('Test figure')

Are there any inbuilt function in Matlab to do the same… Thanks

  • so you want to set a datapoint in the first subplot and also get the according values at the same position of the other subplot? – Robert Seifert Oct 30 '13 at 13:45
  • not exactly.. I will summarize once again when you have to analyse the bigger measurement files with more number of signals... We use to move the cursor over the screen and at each point of timestamp you are able to read the values from different signals. I am expecting something like this... I am not aware if we can call thin using a inbuilt function. – Bu Bu Bulji Oct 30 '13 at 13:48
  • I'm quite sure you can solve your problem using [customized DataTipCursors](http://undocumentedmatlab.com/blog/controlling-plot-data-tips/). But if you like to get help on that you probably need to improve your question. ("real" data, desired plot, what values do you want to obtain ... ) – Robert Seifert Oct 30 '13 at 14:13
  • @thewaywewalk [IMG]http://i42.tinypic.com/i5njvn.jpg[/IMG] Attached you could see the image. on the right side of the pic you can find different signal names. when i move my cursor in the middle of the screen i can see the values of each signal varies corresponding to each 'x' timepoint. the uploaded image is from the internal office tool. I have to make analysis in matlab using scripts but i want to have the above mentioned function. is it possible? hope my question was clear now. Thanks – Bu Bu Bulji Oct 31 '13 at 06:48

2 Answers2

0

ginput might be what you're looking for.

Here's an example. Hopefully you can adapt it to do what you want.

xData = 11:20;
data1 = rand(1, 10);
data2 = rand(1, 10);

ax1 = subplot(2, 1, 1);
plot(xData,data1)
hold on
ax2 = subplot(2, 1, 2);
plot(xData,data2)
hold on

[x,y] = ginput(1); % get one input point

% plot and label that point in the first subplot
axes(ax1)
plot(x, y, 'ro')
text(x, y, ['   x = ', num2str(x), 'y = ', num2str(y)])

% label that point in the second subuplot
axes(ax2)
plot(x, y, 'go')
text(x, y, ['   x = ', num2str(x), 'y = ', num2str(y)])
Molly
  • 13,240
  • 4
  • 44
  • 45
  • somewhat similar to this.. when i use the above command, i should click on some point and retrieve those data from command window. either is there any possibility to view those values directly in the plot window while moving the cursor on the plot screen? – Bu Bu Bulji Oct 31 '13 at 06:42
  • I've added an example. I don't think there is a single function to do what you want but you should be able write something. – Molly Oct 31 '13 at 15:17
0

To achieve what you look for you may want to define the WindowButtonMotionFunction-callback in the figure properties. The callback fires whenever you move the mouse, and from the mouse position (currentPoint of the current axes), you can then update whatever data viewer you have created.

For your reading pleasure, here the help to the WindowButtonMotionFunction out of the help:

WindowButtonMotionFcn
function handle | cell array containing function handle and additional arguments | string (not recommended)

Mouse motion callback function. Executes whenever you move the pointer within the figure window. Define the WindowButtonMotionFcn as a function handle. The function must define at least two input arguments (handle of figure associated with key release and an event structure).

See Function Handle Callbacks for information on how to use function handles to define the callback function.

Example Using All Window Button Properties

Click to view in editor — This example enables you to use mouse motion to draw lines. It uses all three window button functions.

Click to run example — Click the left mouse button in the axes and move the cursor, left-click to define the line end point, right-click to end drawing mode.
Jonas
  • 74,690
  • 10
  • 137
  • 177
  • http://tinypic.com/view.php?pic=i5njvn&s=5 Attached you could see the image. on the right side of the pic you can find different signal names. when i move my cursor in the middle of the screen i can see the values of each signal varies corresponding to each 'x' timepoint. the uploaded image is from the internal office tool. I have to make analysis in matlab using scripts but i want to have the above mentioned function. is it possible? hope my question was clear now. Thanks – Bu Bu Bulji Oct 31 '13 at 06:44
  • @BuBuBulji: so you need to define the WindowButtonMotionFunction-callback that reads out the x-position within the graph and updates the numbers on the right? Yes, that is definitely possible. – Jonas Oct 31 '13 at 19:01
  • Thanks for your comment. I am a newbie to Matlab, can you post some example code or so for better understanding... I am working with Matlab R2010B version, do this >'WindowButtonMotionFunction' function is already enabled in the above mentioned version as i could not get it from 'help'.. Thanks in advance. – Bu Bu Bulji Nov 04 '13 at 10:12
  • @BuBuBulji: First, you need to write a function that takes a handle and a dummy argument as input. This is the function that should be executed whenever the mouse moves. Using the handle (the figure handle), you can then query the axes handle, and read the current x and y axis values from the axes' `currentpoint` property. Then, you attach the callback to the figure as `set(handleOfTheFigure,'WindowButtonMotionFunction',@yourFunction)` – Jonas Nov 05 '13 at 14:41