simple gui2

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

 Risposta accettata

Walter Roberson
Walter Roberson il 22 Mar 2011

0 voti

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.

Più risposte (3)

bing zeth
bing zeth il 24 Mar 2011

0 voti

im now trying uigetfile/uigetdir in this case.. still confuse with this command. i also used evalin to display the figure and there are errors

1 Commento

Walter Roberson
Walter Roberson il 24 Mar 2011
Example:
[filename, pathname] = uigetfile('Choose the input file');
completepath = fullfile(pathname, filename);
data = load(completepath);
fn = fieldnames(data);
current_data = data.(fn{1});

Accedi per commentare.

bing zeth
bing zeth il 28 Mar 2011

0 voti

is there any way i can display the figure without opening the box the contains my file? i want it to display right away after i click the pushbutton

2 Commenti

Walter Roberson
Walter Roberson il 28 Mar 2011
If you already know the path to the file, then
data = load(completepath);
fn = fieldnames(data);
current_data = data.(fn{1});
bing zeth
bing zeth il 4 Apr 2011
data = load(completepath);
>>actually,how to write the completepath? I dont want to use the uigetfile command,i want the figure displays right away

Accedi per commentare.

bing zeth
bing zeth il 4 Apr 2011

0 voti

my file is masum.jpg

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by