Remnants of MATLAB Popup Selection Example Stay There - matlab

I am still learning my way around MATLAB's gui. I used one of GUIDE's templates, precisely the GUI with Axes and Menu.
This generates two files: GUIFigure.m and GUIFigure.fig
At first, I deleted the line that gives labels to the popup menu which goes along the following lines:
function popupmenu1_CreateFcn(hObject, eventdata, handles)
set(hObject, 'String', {'old text 1', 'old text 2');
When I replaced the text inside the curly brackets with my own text, it worked fine. When I replaced it with a cell variable and used incorrect syntax, it would give me an error, which is understandable, but the figure would still pop up with the old text.
Another similar issue is that the example already has a plot with axes. Now I deleted the axes from the .fig file, and I also deleted their code in the .m file. However when I run the gui function, the axes still show up with the plot, although I've even deleted the code that generates the data for the plot!
Any explanation/tips as to what is going on would be appreciated.
function varargout = FIAFigure(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #FIAFigure_OpeningFcn, ...
'gui_OutputFcn', #FIAFigure_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before FIAFigure is made visible.
function FIAFigure_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for FIAFigure
handles.output = hObject;
handles.dataSetsCell = varargin{1};
handles.categoryNames = varargin{2};
% Update handles structure
guidata(hObject, handles);
if strcmp(get(hObject,'Visible'),'off')
plot(rand(5));
end
% --- Outputs from this function are returned to the command line.
function varargout = FIAFigure_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
t = uitable(handles.uitable1);
cla;
popup_sel_index = get(handles.popupmenu1, 'Value');
set(t,'Data',magic(popup_sel_index))
% --------------------------------------------------------------------
function FileMenu_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function OpenMenuItem_Callback(hObject, eventdata, handles)
file = uigetfile('*.fig');
if ~isequal(file, 0)
open(file);
end
% --------------------------------------------------------------------
function PrintMenuItem_Callback(hObject, eventdata, handles)
printdlg(handles.figure1)
% --------------------------------------------------------------------
function CloseMenuItem_Callback(hObject, eventdata, handles)
selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
['Close ' get(handles.figure1,'Name') '...'],...
'Yes','No','Yes');
if strcmp(selection,'No')
return;
end
delete(handles.figure1)
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
set(hObject, 'String', {handles.categoryNames{1:end}});
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function uitable1_CreateFcn(hObject, eventdata, handles)

Related

Matlab Guide Button Glitch-

I am trying to make it such that I display an average of four numbers and a function which takes the average as its input. However, if a pushbutton is pressed I want the function to display "0". Below is my attempt, but the problem is that I am attempting to store the state of the button in handles.button_state but my value does not seem to store properly, as the global variable stays to my initialized value of false, and the problem is that my if statement to either display the function or the value "0" always displays the value of the function if I press my "calculate" button more than once, instead of staying "0" if the button is pressed.
function varargout = Real2(varargin)
% REAL2 MATLAB code for Real2.fig
% REAL2, by itself, creates a new REAL2 or raises the existing
% singleton*.
%
% H = REAL2 returns the handle to a new REAL2 or the handle to
% the existing singleton*.
%
% REAL2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in REAL2.M with the given input arguments.
%
% REAL2('Property','Value',...) creates a new REAL2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Real2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Real2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Real2
% Last Modified by GUIDE v2.5 07-Feb-2017 18:09:44
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #Real2_OpeningFcn, ...
'gui_OutputFcn', #Real2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Real2 is made visible.
function Real2_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 Real2 (see VARARGIN)
% Choose default command line output for Real2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
initialize_gui(hObject, handles, false);
% UIWAIT makes Real2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Real2_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
%-----------------------------------------------------------------------------------%
function Number1_Callback(hObject, eventdata, handles)
Number1 = str2double(get(hObject, 'String'));
handles.metricdata.Number1 = Number1;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function Number1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%-----------------------------------------------------------------------------------%
function Number2_Callback(hObject, eventdata, handles)
Number2 = str2double(get(hObject, 'String'));
handles.metricdata.Number2 = Number2;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function Number2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%-----------------------------------------------------------------------------------%
function Number3_Callback(hObject, eventdata, handles)
Number3 = str2double(get(hObject, 'String'));
handles.metricdata.Number3 = Number3;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function Number3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Number4_Callback(hObject, eventdata, handles)
Number4 = str2double(get(hObject, 'String'));
handles.metricdata.Number4 = Number4;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function Number4_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%-----------------------------------------------------------------------------------%
% --------------------------------------------------------------------
% --- Executes on button press in Togz.
function Togz_Callback(hObject, eventdata, handles)
% hObject handle to Togz (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of Togz
button_state = get(hObject,'Value');
handles.button_state = button_state;
set(handles.funcz, 'String', 0);
%-----------------------------------------------------------------------------------%
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
average = (handles.metricdata.Number1+handles.metricdata.Number2+handles.metricdata.Number3+handles.metricdata.Number4)/4;
funcz= 2*average^2-3*average+2;
set(handles.average, 'String', average);
if handles.button_state==true
set(handles.funcz, 'String', 0);
else
set(handles.funcz, 'String', funcz);
end
function initialize_gui(fig_handle, handles, isreset)
% If the metricdata field is present and the reset flag is false, it means
% we are we are just re-initializing a GUI by calling it from the cmd line
% while it is up. So, bail out as we dont want to reset the data.
if isfield(handles, 'metricdata') && ~isreset
return;
end
handles.metricdata.Number1 = 0;
handles.metricdata.Number2 = 0;
handles.metricdata.Number3 = 0;
handles.metricdata.Number4 = 0;
handles.button_state = false;
set(handles.Number1, 'String', handles.metricdata.Number1);
set(handles.Number2, 'String', handles.metricdata.Number2);
set(handles.Number3, 'String', handles.metricdata.Number3);
set(handles.Number4, 'String', handles.metricdata.Number4);
set(handles.funcz, 'String', 1);
set(handles.average, 'String', 0);
% Update handles structure
guidata(handles.figure1, handles);
handles is not a global variable but rather it is stored within the figure itself and automatically passed to all callbacks as the third input. If you want to make a modification to the handles structure, you have to save the changes to the handles structure by re-assigning it to the figure using guidata.
% Change the value
handles.button_state = button_state;
% "Save" these changes
guidata(hObject, handles)

Matlab - Defining the maximum value of a slider with a pushbutton_callback

I have a GUI. Suppose I want to display a certain number of images. I created a slider to display all the images in one window when you scroll down. The problem occurrs when you scroll down and exceed the number of images, so I need something to control the maximum value of the slider
One solution to this is:
I can create a slider in certain position and with certain max depending on images I selected .
My code right now (does not have the solution I spoke about) :
function varargout = panel(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #panel_OpeningFcn, ...
'gui_OutputFcn', #panel_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function panel_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = panel_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
global celldata3;
k = 1;
[filename pathname] = uigetfile({'*.*'},'File Selector','MultiSelect', 'on')
iscellstr(filename)
celldata1 = cellstr(pathname)
celldata2 = cellstr(filename)
celldata3 = strcat(celldata1,celldata2)
subplot(3,4,1),imshow(celldata3{1})
subplot(3,4,2),imshow(celldata3{2})
subplot(3,4,3),imshow(celldata3{3})
subplot(3,4,4),imshow(celldata3{4})
subplot(3,4,5),imshow(celldata3{5})
subplot(3,4,6),imshow(celldata3{6})
subplot(3,4,7),imshow(celldata3{7})
subplot(3,4,8),imshow(celldata3{8})
subplot(3,4,9),imshow(celldata3{9})
subplot(3,4,10),imshow(celldata3{10})
subplot(3,4,11),imshow(celldata3{11})
subplot(3,4,12),imshow(celldata3{12})
function slider1_Callback(hObject, eventdata, handles)
global celldata3;
a = get(hObject,'Value')
b = get(hObject,'Max')
[n max] = size(celldata3)
%set(handles.text2,'string',a)
i = (b-a)*4
if i+12 >= max
display ('STOP!');
end
subplot(3,4,1),imshow(celldata3{i+1})
subplot(3,4,2),imshow(celldata3{i+2})
subplot(3,4,3),imshow(celldata3{i+3})
subplot(3,4,4),imshow(celldata3{i+4})
subplot(3,4,5),imshow(celldata3{i+5})
subplot(3,4,6),imshow(celldata3{i+6})
subplot(3,4,7),imshow(celldata3{i+7})
subplot(3,4,8),imshow(celldata3{i+8})
subplot(3,4,9),imshow(celldata3{i+9})
subplot(3,4,10),imshow(celldata3{i+10})
subplot(3,4,11),imshow(celldata3{i+11})
subplot(3,4,12),imshow(celldata3{i+12})
display (i+12)
function slider1_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function slider1_ButtonDownFcn(hObject, eventdata, handles)

How to declare static and global variable in MATLAB

I am using a function of increase and decrease sharpness, contrast of an image but the problem is that I have to get the value of the increased or decreased sharpness or contrast value from the functions to reuse those values. the function of increase and decrease of sharpness or contrast happens when the button is clicked in the GUI. Kindly help me to use and declare static and global variables which will be used in the application.
Main GUI File
function varargout = Cotton_Disease_Detector(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #Cotton_Disease_Detector_OpeningFcn, ...
'gui_OutputFcn', #Cotton_Disease_Detector_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function Cotton_Disease_Detector_OpeningFcn(hObject, eventdata, handles, varargin)
axes(handles.axes1);
axis off
axes(handles.axes4);
axis off
axes(handles.axes5);
axis off
axes(handles.axes6);
axis off
handles.output = hObject;
guidata(hObject, handles);
function varargout = Cotton_Disease_Detector_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function browse_Callback(hObject, eventdata, handles)
image=browseImage();
imshow(image,'Parent',handles.axes1)
function segmentation_image_Callback(hObject, eventdata, handles)
image = imread('enhance.jpg');
image=imageSegmentation(image);
imshow(image,'Parent',handles.axes5);
function enhance_image_Callback(hObject, eventdata, handles)
image=imread('resize.jpg');
set(handles.enhancementPanel,'Visible','On')
image=imageEnhancement(image);
imwrite(image,'enhance.jpg');
imshow(image,'parent',handles.axes4);
function classification_image_Callback(hObject, eventdata, handles)
function feature_extraction_image_Callback(hObject, eventdata, handles)
function decreaseContrast_Callback(hObject, eventdata, handles)
image=imread('enhance.jpg');
[J,x]=decreaseContrast(image,x);
imwrite(J,'enhance.jpg');
imshow(J,'parent',handles.axes4);
function increaseContrast_Callback(hObject, eventdata, handles)
image=imread('enhance.jpg');
[J,x]=increaseContrast(image,x);
imwrite(J,'enhance.jpg');
imshow(J,'parent',handles.axes4);
function decreaseSharpness_Callback(hObject, eventdata, handles)
image=imread('enhance.jpg');
[J,x]=decreaseSharpness(image,x);
imwrite(J,'enhance.jpg');
imshow(J,'parent',handles.axes4);
function increaseSharpness_Callback(hObject, eventdata, handles)
image=imread('enhance.jpg');
[J,x]=increaseSharpness(image,x);
imwrite(J,'enhance.jpg');
imshow(J,'parent',handles.axes4);
function resizeImage_Callback(hObject, eventdata, handles)
image=imread('read.jpg');
image=resizeImage(image);
imwrite(image,'resize.jpg');
Function of increase Sharpness
function [image,x] = increaseSharpness(image,x)
if isempty(x)
x=0.2;
end
x=x+0.2;
image=imsharpen(image,'radius',2,'Amount',x);
end
Function of decrease Sharpness
function [image,x] = decreaseSharpness(image,x)
if isempty(x)
x=0.2;
end
x=x-0.2;
image=imsharpen(image,'radius',2,'Amount',x);
end
The functions of increase decrease Contrast are same as of Sharpness.
Rather than using globals, Matlab provides ways to store data directly on your GUI objects.
This page has a good overview of these methods.
The most appropriate way to share data between calls is to use setappdata(hObject, name, value) to store values on you GUI object and use getappdata(hObject, name) to retrieve them.
Another method is to use the guidata(hObject, data) function allowing you to store a single variable or struct. However, GUIDE GUI's use this function to store a handles object, so the setappdata method is preferred.
[EDIT based on comment from #Hoki]

Passing outside variables to MATLAB GUIDE

My program loads data from a file and produces a graph, the user clicks on an area of interest and then analysis is done and a new graph is produced. The program continues asking the user to click on the image until the user presses e to exit the program.
I want the graph that is produced to be a GUI that takes data from my program but I seem to have trouble transferring that data into the GUI function. Here is a quick example of what my program looks like:
load(data)
plot(x,y)
while 1%so that it continues asking for user interaction
figure(1)
'click on the point you want or press e to exit'
[x1,y1,key]=ginput(1)
f=score(x1,y1)
%the above is a different function that gives us the data that I want to graph,
%that are called xf,yf
%GUI plot
figure(1)
test_gui(xf,yf)
if (key == 'e')
display('End')
break;
else
display('next point')
end
end
My test_gui.m looks like this:
function varargout = test_gui(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #test_gui_OpeningFcn, ...
'gui_OutputFcn', #test_gui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before fft_guide is made visible.
function test_gui_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for test_gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes test_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = test_gui_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
plot (xf,yf)
The problem is that when I click on the "Push" button, it does not graph anything so there must be something wrong in the way I pass the xf, yf variables. I was wondering if anyone has any ideas about what I am doing wrong, I have not used GUIDE before and it seems I'm lost.
From the looks of your code, xf and yf are never defined, only f (the result of score). So that could be why you can't see any plots.
Supposing that score dumps xf and yf into the workspace, you must first define them from varargin and then pass them to the callback function using handles, as Werner commented.
% --- Executes just before fft_guide is made visible.
function test_gui_OpeningFcn(hObject, eventdata, handles, varargin)
xf = varargin{0}; yf = varargin{1}; % Get xf and yf from input
handles.xf = xf; handles.yf = yf; % Put the values in handles
guidata(hObject,handles); % Save handles so you can use it anywhere in the GUI
And in the callback:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
plot (handles.xf,handles.yf)
I believe this should work, supposing xf and yf are being correctly define before being passed to the GUI function.

Use multiple gui and get data from another gui function in matlab

I want to create a gui program with matlab but i want to use multiple gui. for example I have the main gui function and I want to get data from another gui with edit textbox. In the example below, I want to return the p variable to the main gui.
THE MAIN GUI:
function varargout = FoProgram(varargin)
gui_Singleton = 0;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #FoProgram_OpeningFcn, ...
'gui_OutputFcn', #FoProgram_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function FoProgram_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = FoProgram_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function labor_2_Callback(hObject, eventdata, handles)
function fel1_Callback(hObject, eventdata, handles)
cla reset;
clc;
clear all;
n = guzu() %Here I call the second Gui function with edit textbox
uiwait(gcf);
x=linspace(-3*pi,3*pi,1000);
y=sin(x);
plot(x,y,'k','LineWidth',4)
sz='ymcrgbkymcrgbkymcrgbkymcrgbk';
hold on
title('Sin(x) Taylor sora')
%n = str2num(N);
f=zeros(size(x));
for i=1:n
t=(-1)^(i-1)*x.^(2*i-1)/factorial(2*i-1);
f=f+t;
plot(x,f,sz(i),'LineWidth',2)
axis([-10 10 -10 10])
pause(1.5)
hold on
n=n+1;
end
function exit_Callback(hObject, eventdata, handles)
close
THE SECOND GUI
function varargout = guzu(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #guzu_OpeningFcn, ...
'gui_OutputFcn', #guzu_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function guzu_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = guzu_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
p = str2double(get(hObject,'String')) %I want to return this 'p' to the main gui
close
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
This kind of simple user input is easy to accomplish using the inputdlg function, without the need to create a separate GUI - here's an example
inputTitle = 'Input Required';
inputPrompt = 'Enter a value for ''p'':';
userInput = inputdlg(inputTitle, inputPrompt);
if isempty(userInput)
% User cancelled
return;
else
p = userInput{1}; % userInput is a cell array
% Do something with p
end
It may be that the example you provided is a very minimal version of your end-goal for the second UI, so this may not be appropriate (though note that the inputdlg function is capable of some more complex behaviour - see the documentation). If you wish to continue using your separate UI, then you have to make a couple of modifications
%%% Add this line to the end of OpeningFcn
uiwait;
%%% Modify OutputFcn to have the following code:
varargout{1} = str2double(get(handles.edit1, 'String'));
% The figure can be deleted now
% NOTE: You have to change this to the name of your figure,
% if it's not called figure1
delete(handles.figure1);
%%% Add the CloseRequestFcn callback and put this code in it
if isequal(get(hObject, 'waitstatus'), 'waiting')
% The GUI is still in UIWAIT, us UIRESUME
uiresume(hObject);
else
% The GUI is no longer waiting, just close it
delete(hObject);
end
Most of the above is directly copied from here. You can also remove the call to uiwait from FoProgram.