let us consider following program for graphical user interface
function varargout = quadratic(varargin)
% QUADRATIC MATLAB code for quadratic.fig
% QUADRATIC, by itself, creates a new QUADRATIC or raises the existing
% singleton*.
%
% H = QUADRATIC returns the handle to a new QUADRATIC or the handle to
% the existing singleton*.
%
% QUADRATIC('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in QUADRATIC.M with the given input arguments.
%
% QUADRATIC('Property','Value',...) creates a new QUADRATIC or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before quadratic_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to quadratic_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 quadratic
% Last Modified by GUIDE v2.5 23-Jul-2014 18:00:48
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #quadratic_OpeningFcn, ...
'gui_OutputFcn', #quadratic_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 quadratic is made visible.
function quadratic_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 quadratic (see VARARGIN)
% Choose default command line output for quadratic
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes quadratic wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = quadratic_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in edit1.
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
function b_Callback(hObject, eventdata, handles)
% hObject handle to b (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of b as text
% str2double(get(hObject,'String')) returns contents of b as a double
% --- Executes during object creation, after setting all properties.
function b_CreateFcn(hObject, eventdata, handles)
% hObject handle to b (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function c_Callback(hObject, eventdata, handles)
% hObject handle to c (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of c as text
% str2double(get(hObject,'String')) returns contents of c as a double
% --- Executes during object creation, after setting all properties.
function c_CreateFcn(hObject, eventdata, handles)
% hObject handle to c (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- 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)
a=str2num(get(handles.a,'String'));
b=str2num(get(handles.b,'String'));
c=str2num(get(handles.c,'String'));
d=b^2-4*a*c;
if (d>0)
X1=(-b+sqrt(d))/(2*a);
X2=(-b-sqrt(d))/(2*a);
set(handles.x1,'String',X1)
set(handles.x2,'String',X2)
elseif (d==0)
X1=(-b+sqrt(d))/(2*a);
set(handles.x1,'String',X1)
set(handles.x2,'String',X1)
else
set(handles.x1,'String','roots are complex')
set(handles.x2,'String','roots are complex')
end
function x1_Callback(hObject, eventdata, handles)
% hObject handle to x1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of x1 as text
% str2double(get(hObject,'String')) returns contents of x1 as a double
% --- Executes during object creation, after setting all properties.
function x1_CreateFcn(hObject, eventdata, handles)
% hObject handle to x1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function x2_Callback(hObject, eventdata, handles)
% hObject handle to x2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of x2 as text
% str2double(get(hObject,'String')) returns contents of x2 as a double
% --- Executes during object creation, after setting all properties.
function x2_CreateFcn(hObject, eventdata, handles)
% hObject handle to x2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function a_Callback(hObject, eventdata, handles)
% hObject handle to a (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of a as text
% str2double(get(hObject,'String')) returns contents of a as a double
% --- Executes during object creation, after setting all properties.
function a_CreateFcn(hObject, eventdata, handles)
% hObject handle to a (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
this program simple will allow to enter coefficients of quadratic equation and then solve equation and try to find roots,how can i take screenshot of GUI interface after this program?please help me,i want to save figure which occurs after running of this program,thanks in advance
One of the quick and dirty approaches
myGUI = quadratic;
% ......
% do something or wait until it's done...
% ......
print(myGUI, '-dpng', 'GUIOUT.png'); % save as .png
print(myGUI, '-djpeg', 'GUIOUT.jpg'); % save as .jpg
It will work fine if you only take a screenshot.
However, if you encounter the problem for which the output picture does not have the same size as the figure on your screen (especially when saving as pdf), you will probably have to implement solutions describled in
this article.
or even better using fig2file may work for you.
Related
I'm getting this unwanted parse error saying
Error: File: GUI.m Line: 284 Column: 5. Unexpected MATLAB operator.
However, I cannot see any unexpected operator. Can anybody diagnose this issue?
Here's my code:
function varargout = GUI(varargin)
% GUI MATLAB code for GUI.fig
% GUI, by itself, creates a new GUI or raises the existing
% singleton*.
%
% H = GUI returns the handle to a new GUI or the handle to
% the existing singleton*.
%
% GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI.M with the given input arguments.
%
% GUI('Property','Value',...) creates a new GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUI_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 GUI
% Last Modified by GUIDE v2.5 24-May-2017 23:28:18
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #GUI_OpeningFcn, ...
'gui_OutputFcn', #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
% End initialization code - DO NOT EDIT
% --- Executes just before GUI is made visible.
function 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 GUI (see VARARGIN)
% Choose default command line output for GUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = GUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in START.
function START_Callback(hObject, eventdata, handles)
% hObject handle to START (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Cfilename;
global Cpathname;
global Tfilename;
global Tpathname;
fid = fopen('C:\Users\Vikcy\Desktop\Flight Images\Values.txt');
tline = fgetl(fid);
C = strsplit(tline,{',',' ','[',']'});
set(handles.fname,'String',C{1,2});
set(handles.shape,'String',C{1,3});
set(handles.shaColor,'String',C{1,4});
set(handles.char,'String',C{1,5});
set(handles.charCol,'String',C{1,6});
set(handles.GLat,'String',C{1,7});
set(handles.GLong,'String',C{1,8});
set(handles.Orient,'String',C{1,9});
Cpathname = 'C:\Users\Vikcy\Desktop\Flight Images\';
Cfilename = 'I.jpg'
Cvar=strcat(Cpathname,Cfilename);
CORI_IMG=imread(Cvar);
%axis(handles.axes1);
%imshow(CORI_IMG);
imshow(CORI_IMG,'Parent',handles.axes1)
Tpathname = 'C:\Users\Vikcy\Desktop\Flight Images\';
Tfilename = C{1,2};
Tvar=strcat(Tpathname,Tfilename);
TORI_IMG=imread(Tvar);
%axis(handles.axes2);
%imshow(TORI_IMG);
imshow(TORI_IMG,'Parent',handles.axes2)
X = strsplit(C{1,1},{'-','.'});
global I;
global J;
I = X{1};
J = X{2};
function fname_Callback(hObject, eventdata, handles)
% hObject handle to fname (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of fname as text
% str2double(get(hObject,'String')) returns contents of fname as a double
% --- Executes during object creation, after setting all properties.
function fname_CreateFcn(hObject, eventdata, handles)
% hObject handle to fname (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function shaColor_Callback(hObject, eventdata, handles)
% hObject handle to shaColor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of shaColor as text
% str2double(get(hObject,'String')) returns contents of shaColor as a double
% --- Executes during object creation, after setting all properties.
function shaColor_CreateFcn(hObject, eventdata, handles)
% hObject handle to shaColor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function char_Callback(hObject, eventdata, handles)
% hObject handle to char (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of char as text
% str2double(get(hObject,'String')) returns contents of char as a double
% --- Executes during object creation, after setting all properties.
function char_CreateFcn(hObject, eventdata, handles)
% hObject handle to char (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function charCol_Callback(hObject, eventdata, handles)
% hObject handle to charCol (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of charCol as text
% str2double(get(hObject,'String')) returns contents of charCol as a double
% --- Executes during object creation, after setting all properties.
function charCol_CreateFcn(hObject, eventdata, handles)
% hObject handle to charCol (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function GLat_Callback(hObject, eventdata, handles)
% hObject handle to GLat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of GLat as text
% str2double(get(hObject,'String')) returns contents of GLat as a double
% --- Executes during object creation, after setting all properties.
function GLat_CreateFcn(hObject, eventdata, handles)
% hObject handle to GLat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function GLong_Callback(hObject, eventdata, handles)
% hObject handle to GLong (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of GLong as text
% str2double(get(hObject,'String')) returns contents of GLong as a double
% --- Executes during object creation, after setting all properties.
function GLong_CreateFcn(hObject, eventdata, handles)
% hObject handle to GLong (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
end
set(hObject,'BackgroundColor','white');
function shape_CreateFcn(hObject, eventdata, handles)
% hObject handle to shape (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Orient_Callback(hObject, eventdata, handles)
% hObject handle to Orient (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Orient as text
% str2double(get(hObject,'String')) returns contents of Orient as a double
function Orient_CreateFcn(hObject, eventdata, handles)
% hObject handle to Orient (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
% --- 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)
% --- Executes on button press in CANCEL.
function CANCEL_Callback(hObject, eventdata, handles)
% hObject handle to CANCEL (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function gLat2_Callback(hObject, eventdata, handles)
% hObject handle to gLat2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of gLat2 as text
% str2double(get(hObject,'String')) returns contents of gLat2 as a double
% --- Executes during object creation, after setting all properties.
function gLat2_CreateFcn(hObject, eventdata, handles)
% hObject handle to gLat2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function gAlt_Callback(hObject, eventdata, handles)
% hObject handle to gAlt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of gAlt as text
% str2double(get(hObject,'String')) returns contents of gAlt as a double
% --- Executes during object creation, after setting all properties.
function gAlt_CreateFcn(hObject, eventdata, handles)
% hObject handle to gAlt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit12_Callback(hObject, eventdata, handles)
% hObject handle to edit12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit12 as text
% str2double(get(hObject,'String')) returns contents of edit12 as a double
% --- Executes during object creation, after setting all properties.
function edit12_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function GBear_Callback(hObject, eventdata, handles)
% hObject handle to GBear (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of GBear as text
% str2double(get(hObject,'String')) returns contents of GBear as a double
% --- Executes during object creation, after setting all properties.
function GBear_CreateFcn(hObject, eventdata, handles)
% hObject handle to GBear (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in NEXT.
function NEXT_Callback(hObject, eventdata, handles)
% hObject handle to NEXT (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function shape_Callback(hObject, eventdata, handles)
% hObject handle to shape (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of shape as text
% str2double(get(hObject,'String')) returns contents of shape as a double
%fid = fopen('C:\Users\Vikcy\Desktop\Files\Values.txt');
%C = textscan(fid, '%s')
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on button press in preTar.
function preTar_Callback(hObject, eventdata, handles)
% hObject handle to preTar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Tfilename;
global Tpathname;
global I;
global J;
J=int32(str2num(J));
J=J-1;
J=int2str(J);
Tfilename = strcat(I,'-',J,'.jpg');
fid = fopen('C:\Users\Vikcy\Desktop\Flight Images\Values.txt');
for i = 1:count
tline = fgetl(fid);
end
C = strsplit(tline,{',',' ','[',']'});
set(handles.fname,'String',C{1,2});
set(handles.shape,'String',C{1,3});
set(handles.shaColor,'String',C{1,4});
set(handles.char,'String',C{1,5});
set(handles.charCol,'String',C{1,6});
set(handles.GLat,'String',C{1,7});
set(handles.GLong,'String',C{1,8});
set(handles.Orient,'String',C{1,9});
Cpathname = 'C:\Users\Vikcy\Desktop\Flight Images\';
Cfilename = 'I.jpg'
Cvar=strcat(Cpathname,Cfilename);
CORI_IMG=imread(Cvar);
%axis(handles.axes1);
%imshow(CORI_IMG);
imshow(CORI_IMG,'Parent',handles.axes1)
Tpathname = 'C:\Users\Vikcy\Desktop\Flight Images\';
Tvar=strcat(Tpathname,Tfilename);
TORI_IMG=imread(Tvar);
%axis(handles.axes2);
%imshow(TORI_IMG);
imshow(TORI_IMG,'Parent',handles.axes2)
axes(handles.axes1);
imshow(image)
% --- Executes on button press in nexTar.
function nexTar_Callback(hObject, eventdata, handles)
% hObject handle to nexTar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Tfilename;
global Tpathname;
global I;
global J;
J=int32(str2num(J));
J=J+1
J=int2str(J);
Tfilename = strcat(I,'-',J,'.jpg');
fid = fopen('C:\Users\Vikcy\Desktop\Flight Images\Values.txt');
for i = 1:count
tline = fgetl(fid);
end
C = strsplit(tline,{',',' ','[',']'});
set(handles.fname,'String',C{1,2});
set(handles.shape,'String',C{1,3});
set(handles.shaColor,'String',C{1,4});
set(handles.char,'String',C{1,5});
set(handles.charCol,'String',C{1,6});
set(handles.GLat,'String',C{1,7});
set(handles.GLong,'String',C{1,8});
set(handles.Orient,'String',C{1,9});
Cpathname = 'C:\Users\Vikcy\Desktop\Flight Images\';
Cfilename = 'I.jpg'
Cvar=strcat(Cpathname,Cfilename);
CORI_IMG=imread(Cvar);
%axis(handles.axes1);
%imshow(CORI_IMG);
imshow(CORI_IMG,'Parent',handles.axes1)
Tpathname = 'C:\Users\Vikcy\Desktop\Flight Images\';
Tvar=strcat(Tpathname,Tfilename);
TORI_IMG=imread(Tvar);
%axis(handles.axes2);
%imshow(TORI_IMG);
imshow(TORI_IMG,'Parent',handles.axes2)
axes(handles.axes1);
imshow(image)
From the Matlab documentation:
Functions end with either an end statement, the end of the file, or the definition line for a local function, whichever comes first. The end statement is required if:
Any function in the file contains a nested function (a function completely contained within its parent).
The function is a local function within a function file, and any local function in the file uses the end keyword.
The function is a local function within a script file.
You use the end keyword in your function Orient_CreateFcn, so all of your local functions require an end statement.
This is good coding practise anyway, as it makes your code more clear. For example it clarifies whether a local function is nested or not without having to find the parent function's end
You have an extra end on line 45, just delete it. See below
gui_mainfcn(gui_State, varargin{:});
end
end % <- this one
I am trying to create a GUI using GUIDE where it allows the user to pick one of two pushbuttons. The strings in the pushbuttons will vary each time (I haven't automated this yet), but when any of the pushbuttons is pushed, I'd like the GUI to put out the string as an output variable.
I have the code to where it shows the output in the workspace, but the handles are deleted before the OutputFn is called. Any suggestions on how to fix this?
Also, I'd like to use a 'Next' button. Ideally this should pull up the next two texts to be displayed on the pushbuttons, in an iterative manner, but I'd be happy to move past the hurdle of getting the output for now.Here is what I have so far:
function varargout = Select_A_B(varargin)
% SELECT_A_B MATLAB code for Select_A_B.fig
% SELECT_A_B, by itself, creates a new SELECT_A_B or raises the existing
% singleton*.
%
% H = SELECT_A_B returns the handle to a new SELECT_A_B or the handle to
% the existing singleton*.
%
% SELECT_A_B('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SELECT_A_B.M with the given input arguments.
%
% SELECT_A_B('Property','Value',...) creates a new SELECT_A_B or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Select_A_B_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Select_A_B_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 Select_A_B
% Last Modified by GUIDE v2.5 18-Jun-2015 15:12:42
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #Select_A_B_OpeningFcn, ...
'gui_OutputFcn', #Select_A_B_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 Select_A_B is made visible.
function Select_A_B_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 Select_A_B (see VARARGIN)
% Choose default command line output for Select_A_B
handles.output = hObject;
handles.string = '';
if isempty(varargin)
varargin{1} = 1;
varargin{2} = 1;
end
text1 = varargin{1};
text2 = varargin{2};
A = {'Apple';'Orange'};
B = {'Football';'Basketball'};
set(handles.pushbutton1,'string',A(text1)); % wait until we're ready
set(handles.pushbutton2,'string',B(text2)); % wait until we're ready
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Select_A_B wait for user response (see UIRESUME)
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Select_A_B_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = hObject;
varargout{2} = handles.string;
% --- 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)
selectedButton = get(hObject,'String')
set(handles.string,'String',selectedButton);
guidata(hObject, handles);
close(gcf);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
selectedButton = get(hObject,'String')
set(handles.string,'String',selectedButton);
guidata(hObject, handles);
close(gcf);
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function pushbutton1_CreateFcn(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
I have the answer to my question. A summary of changes:
Added uiresume (after adding uiwait in the Opening function) after each Callback
Deleted close (gcf) after each Callback; if the figure closes, then hObject and handles in guidata are no longer accessible to the Output function
Created a handle structure to contain the text of interest and saved that in
guidata after each Callback function
Saved the output from guidata to a .mat file in the Output function
% --- 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)
selectedButton = get(hObject,'String')
handles.string = selectedButton;
guidata(hObject, handles);
uiresume(handles.figure1);
% close(gcf);
function varargout = Select_A_B_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = hObject;
varargout{2} = handles.string;
save 'guioutput'
delete(hObject)
Learnings from the post experience:
I should’ve been more specific regarding my question. Hopefully I’ll
get better with more experience and learning the correct ‘lingo’ to
use.
I should’ve pointed out in my first post that I did spend
considerable time looking at multiple blogs and sites on Matlab GUI,
guide, and guidata. Frankly, none of the sites that I found addressed
my specific question.
This post is the one that finally helped me figure out my mistake:
http://www.mathworks.com/matlabcentral/answers/141809-issue-with-gui-editbox-callback
I want to create a graphical interface with the GUIDE Matlab that displays diffrent responses of a transfer function : step , impulse , bode , nyquist and nichols responses.
it works fine for the step and impulse responses but with nyquist , bode and nichols it dosen't work , i should add 'squeeze' to the 'plot' function but it's not exactly the correct response !
this is the error when i try with plot only :
??? Error using ==> plot Data may not have more than 2 dimensions
This is th LTI.fig file
The following code is the content of the .m file
function varargout = LTI(varargin)
% LTI M-file for LTI.fig
% LTI, by itself, creates a new LTI or raises the existing
% singleton*.
%
% H = LTI returns the handle to a new LTI or the handle to
% the existing singleton*.
%
% LTI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in LTI.M with the given input arguments.
%
% LTI('Property','Value',...) creates a new LTI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before LTI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to LTI_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 LTI
% Last Modified by GUIDE v2.5 24-Nov-2014 10:41:38
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #LTI_OpeningFcn, ...
'gui_OutputFcn', #LTI_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 LTI is made visible.
function LTI_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 LTI (see VARARGIN)
% Choose default command line output for LTI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes LTI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = LTI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function numerateur_Callback(hObject, eventdata, handles)
% hObject handle to numerateur (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of numerateur as text
% str2double(get(hObject,'String')) returns contents of numerateur as a double
% --- Executes during object creation, after setting all properties.
function numerateur_CreateFcn(hObject, eventdata, handles)
% hObject handle to numerateur (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function denumerateur_Callback(hObject, eventdata, handles)
% hObject handle to denumerateur (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of denumerateur as text
% str2double(get(hObject,'String')) returns contents of denumerateur as a double
% --- Executes during object creation, after setting all properties.
function denumerateur_CreateFcn(hObject, eventdata, handles)
% hObject handle to denumerateur (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in rep_indic.
function rep_indic_Callback(hObject, eventdata, handles)
% hObject handle to rep_indic (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
num= str2num(get(handles.numerateur,'String'));
denum = str2num(get(handles.denumerateur,'String'));
G=tf([num],[denum]);
axes(handles.figure)
plot(step(G))
grid on
% --- Executes on button press in lieu_bode.
function lieu_bode_Callback(hObject, eventdata, handles)
% hObject handle to lieu_bode (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
num= str2num(get(handles.numerateur,'String'));
denum = str2num(get(handles.denumerateur,'String'));
G=tf([num],[denum]);
axes(handles.figure)
plot(squeeze(bode(G)))
grid on
% --- Executes on button press in rep_impuls.
function rep_impuls_Callback(hObject, eventdata, handles)
% hObject handle to rep_impuls (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
num= str2num(get(handles.numerateur,'String'));
denum = str2num(get(handles.denumerateur,'String'));
G=tf([num],[denum]);
axes(handles.figure)
plot(impulse(G))
grid on
% --- Executes on button press in lieu_nyquist.
function lieu_nyquist_Callback(hObject, eventdata, handles)
% hObject handle to lieu_nyquist (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
num= str2num(get(handles.numerateur,'String'));
denum = str2num(get(handles.denumerateur,'String'));
G=tf([num],[denum]);
axes(handles.figure)
plot(s(nyquist(G)))
grid on
% --- Executes on button press in lieu_nichols.
function lieu_nichols_Callback(hObject, eventdata, handles)
% hObject handle to lieu_nichols (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
num= str2num(get(handles.numerateur,'String'));
denum = str2num(get(handles.denumerateur,'String'));
G=tf([num],[denum]);
axes(handles.figure)
plot(squeeze(nichols(G)))
grid on
You don't provide the *.fig file to go with your code, but I suspect I know what the problem is: bode, nyquist and nichols produce the plot automatically, you don't need to call the plot function. Check the documentation for the correct way to call these functions. In your GUI, replace:
plot(squeeze(bode(G))) by bode(G)
plot(s(nyquist(G))) [sic] by nyquist(G)
plot(squeeze(nichols(G))) by nichols(G)
EDIT based on comments
I think all you need to do is
num= str2num(get(handles.numerateur,'String'));
denum = str2num(get(handles.denumerateur,'String'));
G=tf([num],[denum]);
axes(handles.figure)
step(G)
grid on
and the same applies for bode, nyquist, nichols and impulse, i.e. just create a set of axes in the figure and the plot will be displayed in those axes by default.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
this is what i have so far
as you can see if i use save as i am using right now then i am saving the original image how would i save a modified image after applying one of the filters like black and white.
function varargout = testme(varargin)
% TESTME MATLAB code for testme.fig
% TESTME, by itself, creates a new TESTME or raises the existing
% singleton*.
%
% H = TESTME returns the handle to a new TESTME or the handle to
% the existing singleton*.
%
% TESTME('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TESTME.M with the given input arguments.
%
% TESTME('Property','Value',...) creates a new TESTME or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before testme_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to testme_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 testme
% Last Modified by GUIDE v2.5 13-Oct-2014 13:17:45
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #testme_OpeningFcn, ...
'gui_OutputFcn', #testme_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 testme is made visible.
function testme_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 testme (see VARARGIN)
% Choose default command line output for testme
handles.fileLoaded = 0;
handles.fileLoaded2 = 0;
%-----------------------------------------------------------------------
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes testme wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = testme_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in loadbutton.
function loadbutton_Callback(hObject, eventdata, handles)
% hObject handle to loadbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im im2
[path,user_cance]=imgetfile();
if user_cance
msgbox(sprintf('Error'),'Error','Error');
return
end
im=imread(path);
im=im2double(im); %converts to double
im2=im; %for backup process :)
axes(handles.axes1);
imshow(im);
axes(handles.axes2);
hist(im);
%-----------------------------------------------------------------------
% --- Executes on button press in resetbutton.
function resetbutton_Callback(hObject, eventdata, handles)
% hObject handle to resetbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im2
axes(handles.axes1);
imshow(im2);
axes(handles.axes2);
hist(im2);
% --- Executes on button press in negativebutton.
function negativebutton_Callback(hObject, eventdata, handles)
% hObject handle to negativebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im
imblack=im;
imblack=1-im;
axes(handles.axes1);
imshow(imblack);
axes(handles.axes2);
hist(imblack);
% --- Executes on button press in greybutton.
function greybutton_Callback(hObject, eventdata, handles)
% hObject handle to greybutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im
imgray=(im(:,:,1)+im(:,:,2)+im(:,:,2))/3;
axes(handles.axes1);
imshow(imgray);
axes(handles.axes2);
hist(imgray);
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global im2
val=0.5*get(hObject,'Value')-0.5;
imbright=im2+val;
axes(handles.axes1);
imshow(imbright);
axes(handles.axes2);
hist(imbright);
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on button press in savebutton.
function savebutton_Callback(hObject, eventdata, handles)
% hObject handle to savebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[file,path]=uiputfile({'*.bmp','BMP'},'Save Image As');
f=getframe(handles.axes1);
[x,map]=frame2im(f);
imwrite(x,fullfile(path, file),'bmp');
% --- Executes on button press in black.
function black_Callback(hObject, eventdata, handles)
% hObject handle to black (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
global im
xb=im;
b=im2bw(xb);
imshow(b);
There are several ways to do this, but maybe a good way is to store the image (after applying a filter) in the figure's application data. You can do this with guidata.
After each filter you store the image;
% --- Executes on button press in black.
function black_Callback(hObject, eventdata, handles)
% hObject handle to black (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
global im
xb=im;
b=im2bw(xb);
imshow(b);
% Store the image
handles.image = b;
guidata(hObject, handles);
Then in your savebutton_Callback, simply refer to handles.image;
I'm making a GUI for the Bisection method in matlab and when I push the button to calculate the root I'm displaying the result in a text box field called rezInput.
If I open the *.m file and run the gui from here - everything works.
The problem:
If I directly open the *.fig file, enter the values (function, interval, tolerance) and press the button I get an error 'rezInput field does not exist'.
Here's the error:
??? Reference to non-existent field 'rezInput'.
Error in ==> mBisectoarei>calcBtn_Callback at 212
set(handles.rezInput, 'String', num2str(xr));
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> mBisectoarei at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
#(hObject,eventdata)mBisectoarei('calcBtn_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
... and the entire code:
function varargout = mBisectoarei(varargin)
% MBISECTOAREI M-file for mBisectoarei.fig
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #mBisectoarei_OpeningFcn, ...
'gui_OutputFcn', #mBisectoarei_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 mBisectoarei is made visible.
function mBisectoarei_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 mBisectoarei (see VARARGIN)
% Choose default command line output for mBisectoarei
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes mBisectoarei wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = mBisectoarei_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function functieInput_Callback(hObject, eventdata, handles)
% hObject handle to functieInput (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of functieInput as text
% str2double(get(hObject,'String')) returns contents of functieInput as a double
functie = get(hObject,'String');
% save new value to global hObject for later use
handles.tb.functie = functie;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function functieInput_CreateFcn(hObject, eventdata, handles)
% hObject handle to functieInput (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function intervalA_Callback(hObject, eventdata, handles)
% hObject handle to intervalA (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of intervalA as text
% str2double(get(hObject,'String')) returns contents of intervalA as a double
intA = str2num(get(hObject,'String'));
% save new value to global hObject for later use
handles.tb.intA = intA;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function intervalA_CreateFcn(hObject, eventdata, handles)
% hObject handle to intervalA (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function intervalB_Callback(hObject, eventdata, handles)
% hObject handle to intervalB (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of intervalB as text
% str2double(get(hObject,'String')) returns contents of intervalB as a double
intB = str2num(get(hObject,'String'));
% save new value to global hObject for later use
handles.tb.intB = intB;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function intervalB_CreateFcn(hObject, eventdata, handles)
% hObject handle to intervalB (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function tolInput_Callback(hObject, eventdata, handles)
% hObject handle to tolInput (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of tolInput as text
% str2double(get(hObject,'String')) returns contents of tolInput as a double
tol = str2double(get(hObject,'String'));
% save new value to global hObject for later use
handles.tb.tol = tol;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function tolInput_CreateFcn(hObject, eventdata, handles)
% hObject handle to tolInput (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in calcBtn.
function calcBtn_Callback(hObject, eventdata, handles)
% hObject handle to calcBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% BEGIN mBisectoarei
f = inline(handles.tb.functie);
xl = handles.tb.intA;
xu = handles.tb.intB;
tol = handles.tb.tol;
if f(xu)*f(xl)<0
else
set(handles.rezInput, 'String', 'Interval gresit!');
end
for i=2:1000
xr=(xu+xl)/2;
if f(xu)*f(xr)<0
xl=xr;
else
xu=xr;
end
if f(xl)*f(xr)<0
xu=xr;
else
xl=xr;
end
xnew(1)=0;
xnew(i)=xr;
if abs((xnew(i)-xnew(i-1))/xnew(i))<tol,break,end
end
set(handles.rezInput, 'String', num2str(xr));
function rezInput_Callback(hObject, eventdata, handles)
% hObject handle to rezInput (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of rezInput as text
% str2double(get(hObject,'String')) returns contents of rezInput as a double
% --- Executes during object creation, after setting all properties.
function rezInput_CreateFcn(hObject, eventdata, handles)
% hObject handle to rezInput (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
MATLAB GUIS cannot be run by directly opening .fig files. Take a look at this MathWorks link. Under the section labeled "Save the GUI Layout," find paragraph six (6). Under the screenshot, you will see a "Note:" that explains your problem.