Please help me i get the error "Undefined function or variable 'varargin'. Error in Question4 (line 16) gui_mainfcn(gui_State, varargin{:});"
이전 댓글 표시
function varargout = Question4(varargout)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Question4_OpeningFcn, ...
'gui_OutputFcn', @Question4_OutputFcn, ...
'gui_LayoutFcn', [], ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargin{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function open_Callback(hObject, evendata, handles)
a = imread('cristiano-ronaldo-goal-lebron-zlatan-01-960x640.jpg')
imshow(flip(a,1));
function Question4_OpeningFcn(hObject, evendata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function horizontal_Callback(hObject, evendata, handles)
a = imread('cristiano-ronaldo-goal-lebron-zlatan-01-960x640.jpg');
imshow(flip(a,1));
function vertical_Callback(hObject, evendata, handles)
a = imread('cristiano-ronaldo-goal-lebron-zlatan-01-960x640.jpg');
imshow(flip(a,2));
답변 (2개)
Geoff Hayes
2018년 4월 26일
Phiri - your function signature is
function varargout = Question4(varargout)
where the input and output parameters/arguments are the same name. I think the input should be variable argument in or varargin
function varargout = Question4(varargin)
댓글 수: 10
Phiri Tanaka
2018년 4월 26일
편집: Phiri Tanaka
2018년 4월 26일
Walter Roberson
2018년 4월 26일
Using varargin in the function definition is the correct thing to do.
We would need to see the error messages and code that was relevant to them.
Phiri Tanaka
2018년 4월 26일
편집: Walter Roberson
2018년 4월 26일
Walter Roberson
2018년 4월 26일
"Unable to read file 'Question4.fig'. No such file or directory."
Well that should be self-explanatory. You do not have a Question4.fig file. GUIDE-created interfaces create a .fig file along with the .m file, and you need both.
One way this problem can arise is if you took a GUIDE-created .m file and renamed it without renaming the .fig as well.
On the other hand, you should not just rename the .m and .fig files, as some of what is created by GUIDE depends upon the file name. You should instead go into GUIDE and "Save As" the new name.
Phiri Tanaka
2018년 4월 26일
Walter Roberson
2018년 4월 26일
Rename the files back to the name you used when you created them. Open the GUI inside GUIDE. Then go to the File menu and click on Save As, and select the new name (that is, Question4)
Phiri Tanaka
2018년 4월 26일
Walter Roberson
2018년 4월 26일
Did you write all that code by hand, or did you use GUIDE to create it? GUIDE would have created a .fig file to go along with the .m file. Perhaps you created it in a different directory and moved (or copied) Question4.m without also taking along Question4.fig ?
Phiri Tanaka
2018년 4월 26일
Walter Roberson
2018년 4월 26일
The line
[varargin{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
invokes gui_mainfcn which attempts to load a .fig with the same name as your .m file. gui_mainfcn also is the routine responsible for creating the handles structure, and for calling your Question4_OpeningFcn .
Your code is not creating any uicontrol or menu items, so horizontal_Callback and vertical_Callback have nothing referencing them. You did not set either of them as being callbacks for anything.
In short, if you are going to write your own GUI code without using GUIDE, then you should not use the template that GUIDE uses. You need to instead have code that creates the figure and uicontrol and sets up all appropriate callbacks, and then lets the user interact with the GUI.
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!