From: Christopher on
I'm trying to simply return the coordinates of two mouse clicks that snap to the vertices of some plotted data, using the datacursormode method that is outlined in the help file.

I have read some of the other how-to's and the help and demos and can't seem to figure out why this issue is recurring. I'm hoping it's something imbecilic I'm doing.

Here is my code:

altfig = figure(1);
plot(GGAData(:,1), GGAData(:,6));
datacursormode on;
startpoint = 'No';
dcm_obj = datacursormode(altfig);
set(dcm_obj,'DisplayStyle','window','SnapToDataVertex', 'On');

waitforbuttonpress;
info_struct = getCursorInfo(dcm_obj);

xi(n) = info_struct.Position(1);
yi(n) = info_struct.Position(2); % get position of first point, set as index n
plot(xi(n),yi(n),'ro') %leave a mark for selected point

index(n) = info_struct.DataIndex;

waitforbuttonpress;
info_struct = getCursorInfo(dcm_obj);

xi(k) = info_struct.Position(1);
yi(k) = info_struct.Position(2); %get position of second point, set as index k
plot(xi(k),yi(k),'ro') % leave a mark for second point

index(k) = info_struct.DataIndex;
From: Christopher on
By the way, the error I'm getting is the fabled "Attempt to reference field of non-structure array" and it's occurring on the line when I try to take those info_struct.Position(1) and info_struct.Position(2) and save them as my own variables.
From: Christopher on
Anyone? I'm stuck here... hoping it's right in front of my nose... But I can't get this to work. By the way some of this code worked in a previous version of MATLAB, which I find odd.

Ginput will work but it doesn't snap to the data points on a plot, so that doesn't give me what I need.

my infostruct (following even the variable names from the example) appears to always be coming back empty and then when I try to grab the Position from it I get that error...
From: Christopher on
If anyone can help me with this issue I would greatly appreciate it.

I am wondering if it's something with the 2010 version of MATLAB, since the code worked in prior versions. I'm thinking about downloading an older version to test, if I can't get a response here telling me what I'm doing wrong..