简体   繁体   中英

Plotting image and points on Matlab GUI via update function

excuse my noobness, but this is my first post.

i generated this gui in matlab, and i want to plot an image on one of the axis from an update function.

i know in Matlab you can just do something like

image(img) hold on plot(x1,z1) hold off

but how can one do this with the gui?

here is a segment of the update function

%get a handle to the GUI's 'current state' window
deflectionx = findobj('Tag','deflectionx_display');
deflectiony = findobj('Tag','deflectiony_display');
depth = findobj('Tag','depth_display');
Graph = findobj('Tag','Graphical_display');
UltraS = findobj('Tag','UltraS_image');
%update the gui
set(deflectionx,'String',x_def);
set(deflectiony,'String',y_def);
set(depth,'String',insert_depth);


%% above works fine. below does not

%i want this to plot those points on top of the image in the large graph panel of the gui
plot(Graph,img1)
hold on
plot(Graph,x1,z1);
hold off

%this should plot the second image on the UltraS panel
plot(UltraS,img2)

Please and thanks in advance!

So figured it i had to write the handles of the GUI to the workspace in the opening function of the gui

% --- Executes just before VR_gui is made visible.
function VR_gui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to VR_gui (see VARARGIN)

% Choose default command line output for VR_gui
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

%setting axis
needle_plot = handles.Graphical_display;
US_plot = handles.US_image;

%write handle to workspace
assignin ('base','needle_plot',needle_plot);
assignin ('base','US_plot',US_plot);

then read the workspace variables from the update function

needle_plot = evalin('base','needle_plot');
US_plot = evalin('base','US_plot');

axes(US_plot);
image(img2);

axes(needle_plot);
plot(x1,z1,'r--o');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM