how get value at pos(3) position by using "datacursormode on" in axes ???

This is my coding :
%%----->DO 2D CONTOUR MAP<-----%%
B = get(handles.uitable2,'Data');
[C,h] = contourf(B); %countour map the excel in 2D with handles
set(h,'LineWidth',2) %handles line width with "2"
im builde the GUIDE in MATLAB....
The question is, how can i retrieve value at pos(3) position by using "datacursormode on" to display at editbox??? can u continue my command please... URGENT...

1 Kommentar

muhammad - please don't post your question in multiple threads, especially as an answer to another question.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

handles.dcm_obj = datacursormode(hObject);
set(handles.dcm_obj,'Enable','on','UpdateFcn',{@myupdatefcn,hObject});
In the myupdatefcn callback, you will need to define the text string (similar to the output you have shown in the image). As this uses pos, then you have access to the third element which you can set back in the edit text field of your GUI since we are assuming that the hObject passed into this callback (when set above) is the handle to the figure.
function txt = myupdatefcn(~,event_obj,hFigure)
pos = get(event_obj,'Position');
txt = 'something using pos';
handles = guidata(hFigure);
if isfield(handles,'text1')
set(handles.text1,'String',num2str(pos(3)));
end
The above assumes that text1 is the control to update with your text.

6 Kommentare

******SO I FOLLOW YOUR STEP, BUT IT'S STILL DOESN'T WORK...********
  1. function contour_Callback(hObject, eventdata, handles)
  2. % hObject handle to contour (see GCBO)
  3. % eventdata reserved - to be defined in a future version of MATLAB
  4. % handles structure with handles and user data (see GUIDATA)
  5. %%----->DO 2D CONTOUR MAP<-----%%
  6. B = get(handles.uitable2,'Data'); %copy data from table, uitable2
  7. [C,h] = contourf(B); %countour map the excel in 2D with handles
  8. set(h,'LineWidth',2) %handles line width with "2"
  9. set(gca,'YDir','reverse') %reverse the y-scale+excel data (flip up to down)
  10. set(gca,'XAxisLocation','top'); %bring x-axis to the top
  11. colorbar; %display colorbar level
  12. datacursormode on; %enables data cursor mode on current figure
  13. handles.dcm_obj = datacursormode(hObject);
  14. set(handles.dcm_obj,'Enable','on','UpdateFcn',{@myupdatefcn,hObject});
  15. function txt = myupdatefcn(~,event_obj,hFigure)
  16. pos = get(event_obj,'Position');
  17. txt = 'something using pos';
  18. handles = guidata(hFigure);
  19. if isfield(handles,'text1')
  20. set(handles.text1,'String',num2str(pos(3)));
  21. end
  22. set(gca,'FontSize',15,'LineWidth',0.5); %set fontsize+width of axis scale
  23. guidata(hObject, handles);dth of axis scale
  24. # guidata(hObject, handles);
******THIS IS THE ANSWER WHAT I GET AFTER RUN THIS CODING :********
  1. ??? Error using ==> datacursormode at 147
  2. Invalid figure handle
  3. Error in ==> mapping>contour_Callback at 17
  4. handles.dcm_obj = datacursormode(hObjec;
  5. Error in ==> gui_mainfcn at 96
  6. feval(varargin{:});
  7. Error in ==> mapping at 42
  8. gui_mainfcn(gui_State, varargin{:});
  9. Error in ==>
  10. @(hObject,eventdata)mapping('contour_Callback',hObject,eventdata,guidata(hObject))
  11. ??? Error while evaluating uicontrol Callback
Yes, you would need to review all of the code from the link I posted. The hObject that you pass
datacursormode(hObject)
is the handle to the figure hence the error message
Invalid figure handle
since you are passing the handle to a uicontrol (probably a button).
Walter posted a better solution, so I would go with that.
*I FOLLOW YOUR STEP BUT STILL HAS SOME ERROR***
  1. %%----->DO 2D CONTOUR MAP<-----%%
  2. B = get(handles.uitable2,'Data');
  3. axes(handles.axes5); %focus contour map on axes5
  4. [C,h] = contourf(B); %countour map the excel in 2D with handles
  5. set(h,'LineWidth',2) %handles line width with "2"
  6. set(gca,'YDir','reverse') %reverse the y-scale+excel data (flip up to down)
  7. set(gca,'XAxisLocation','top'); %bring x-axis to the top
  8. colorbar; %display colorbar level
handles.dcm_obj = datacursormode(hObject);
datacursormode on
set(handles.dcm_obj,'Enable','on','UpdateFcn',{@myupdatefcn,hObject});
set(gca,'FontSize',15,'LineWidth',0.5); %set fontsize+width of axis scale
guidata(hObject, handles);
function txt = myupdatefcn(~,event_obj,hFigure)
pos = get(event_obj,'Position');
txt = 'something using pos';
handles = guidata(hFigure);
set(handles.text6,'String',num2str(pos(3)));
guidata(hObject, handles);
BUT STILL THE ERROR SHOWS THE PROBLEM AT
handles.dcm_obj = datacursormode(hObject) and other error
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> mapping at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)mapping('contour_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
ACTUALLY Im show the contour map in axes5 not in figure... Is there the error related with this ??
this is both picture, coding and error
i want to get VALUE datacursormode POSITION 3 at axes and display it at edit6.
HOW I WANT TO DO THAT if using an AXES?
and
HOW I WANT TO DO THAT if using figure?
from figure, also tells that "error datatip custom string function"

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by