MATLAB: Simple gui2

simple gui

function simple_gui2 % SIMPLE_GUI2 Select a data set from the pop-up menu, then % click one of the plot-type push buttons. Clicking the button % plots the selected data in the axes.
% Initialize and hide the GUI as it is being constructed. f = figure('Visible','off','Position',[360,500,450,285]); % Construct the components. hsurf = uicontrol('Style','pushbutton','String','Surf',… 'Position',[315,220,70,25],… 'Callback',{@surfbutton_Callback}); hmesh = uicontrol('Style','pushbutton','String','Mesh',… 'Position',[315,180,70,25],… 'Callback',{@meshbutton_Callback}); hcontour = uicontrol('Style','pushbutton',… 'String','Countour',… 'Position',[315,135,70,25],… 'Callback',{@contourbutton_Callback}); %——-add axes——————————————- ha = axes('Units','pixels','Position',[50,60,200,185]); %———————————————————- align([hsurf,hmesh,hcontour],'Center','None'); %———————————————————- % Create the data to plot peaks_data = peaks(35); membrane_data = membrane; [x,y] = meshgrid(-8:.5:8); r = sqrt(x.^2+y.^2) + eps; sinc_data = sin(r)./r;
% Initialize the GUI.
% Change units to normalized so components resize
% automatically.
set([f,hsurf,hmesh,hcontour],...
'Units','normalized');
%Create a plot in the axes.
current_data = peaks_data;
surf(current_data);
% Assign the GUI a name to appear in the window title.
set(f,'Name','Simple GUI')
% Move the GUI to the center of the screen.
movegui(f,'center')
% Make the GUI visibleb.
set(f,'Visible','on');
%----------------------------------------------------------------
% Push button callbacks. Each callback plots current_data in
% the specified plot type.
function surfbutton_Callback(source,eventdata)
% Display surf plot of the currently selected data.
surf(current_data);
end
function meshbutton_Callback(source,eventdata)
% Display mesh plot of the currently selected data.
mesh(current_data);
end
function contourbutton_Callback(source,eventdata)
% Display contour plot of the currently selected data.
contour(current_data);
end
end ___________________________________________________________________ This is the edited m file for simple_gui2. I want to change the figure to the figure frommy file which have the directory path as this one,C:\Users\SONY\Documents\MATLAB\a. How can i put this figure into my figure simple_gui2. I want this figure from the file appears as I click the pushbutton. How should i program it?
Thanks

Best Answer

Replace the line
current_data = peaks_data;
with a line that loads the data from your file and stores the image data array in the variable "current_data". If you want the user to be able to select the file to load, use a call to uigetfile().
Caution: the routines will only work properly for black-and-white or grayscale images. Indexed (pseudocolor) images will not crash the program but will give you different results than you expect. RGB (truecolor) images would crash the program as the processing routines used here are not expecting 3-dimensional arrays.