how to resolve varagout error

function varargout = untitled(varargin)
% UNTITLED M-file for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help untitled
% Last Modified by GUIDE v2.5 07-Apr-2008 19:33:38
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_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 untitled is made visible.
function untitled_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 dat (see GUIDATA)
% varargin command line arguments to untitled (see VARARGIN)
% Choose default command line output for untitled
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled_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 dat (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function dat_Callback(hObject, eventdata, handles)
% hObject handle to dat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user dat (see GUIDATA)
% Hints: get(hObject,'String') returns contents of dat as text
% str2double(get(hObject,'String')) returns contents of dat as a double
% --- Executes during object creation, after setting all properties.
function dat_CreateFcn(hObject, eventdata, handles)
% hObject handle to dat (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in CalcCRC.
function CalcCRC_Callback(hObject, eventdata, handles)
% hObject handle to CalcCRC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user dat (see GUIDATA)
%---------------------------------- My Code -----------------------------%
data=get(handles.dat, 'String') %get the value of data as string
A = strread(data,'%u') % convert data to a coloumn matrix of integers
B=A' %converts the column matrix to row matrix
Divisor=get(handles.divisor, 'String')
C= strread(Divisor,'%u')
D=C'
if (length(B)==7 && length(D)==5)
crc=mycrc(B,D,1) %call mycrc function to generate crc
result=[B,crc]
set(handles.reslt,'String',...
num2str(result)) %set the value of 2nd edit box to result
set(handles.InfoBox,'String',...
['Result : ',...
num2str(result),' ']) %set the value of the text box to result
else
set(handles.InfoBox,'String',...
['Data should be of 7 bits & divisor should be of 5 bits'])
end
function reslt_Callback(hObject, eventdata, handles)
% hObject handle to reslt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user dat (see GUIDATA)
% Hints: get(hObject,'String') returns contents of reslt as text
% str2double(get(hObject,'String')) returns contents of reslt as a double
% --- Executes during object creation, after setting all properties.
function reslt_CreateFcn(hObject, eventdata, handles)
% hObject handle to reslt (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in VerifCRC.
function VerifCRC_Callback(hObject, eventdata, handles)
% hObject handle to VerifCRC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user dat (see GUIDATA)
%------------------------------- My Code -------------------------------%
data=get(handles.reslt, 'String')%get the value of data as string
A = strread(data,'%u') % convert data to a coloumn matrix of integers
B=A' %converts the column matrix to row matrix
Divisor=get(handles.divisor, 'String')
C= strread(Divisor,'%u')
D=C'
check=mycrc(B,D,2) %call mycrc function to check crc
if check==[1] %if check is successful
set(handles.InfoBox,'String',...
[get(handles.InfoBox,'String'),...
'CRC check successful ']) %set the value of the text box to result
end
if check~=[1] %if check is not successful
set(handles.InfoBox,'String',...
[get(handles.InfoBox,'String'),...
'CRC check failed,data got corrupt on the way'])%set the value of the text box to result
end
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over InfoBox.
function InfoBox_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to InfoBox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user dat (see GUIDATA)
% --- Executes on button press in RandmDatGen.
function RandmDatGen_Callback(hObject, eventdata, handles)
% hObject handle to RandmDatGen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user dat (see GUIDATA)
R = rand(1,7)
Y = round(R)
set(handles.dat, 'String',...
num2str(Y))
function divisor_Callback(hObject, eventdata, handles)
% hObject handle to divisor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user dat (see GUIDATA)
% Hints: get(hObject,'String') returns contents of divisor as text
% str2double(get(hObject,'String')) returns contents of divisor as a double
% --- Executes during object creation, after setting all properties.
function divisor_CreateFcn(hObject, eventdata, handles)
% hObject handle to divisor (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
*********************************************************************
there is an error in the code. Please help me out to resolve it. The error is attached herewith.Its urgent please help me out

8 comentarios

Sanjay Tiwari
Sanjay Tiwari el 6 de Ag. de 2019
my email adress; er.sanjaytiwari@hotmail.com
Rik
Rik el 6 de Ag. de 2019
Please use the layout tools to make your code more readable.
GUIDE doesn't close functions with the end keyword. If you pasted a function where you did, the parsing will fail. Did you check if all functions in your file use the same convention?
Sanjay Tiwari
Sanjay Tiwari el 7 de Ag. de 2019
Sorry for the remarks in code. But the issue is not end kewords. I have deleted all the remarks and then try to run the program but the error remains same.
Yes i checked the function but i feel that function varagout is not defined. I have cheked other suggestion and i feel that varagout needs to be defined seperatly and it should be called in this program.
But i am unable to define this varaout. Please look into it.
David Goodmanson
David Goodmanson el 7 de Ag. de 2019
Hi Sanjay, is that last line supposed to be just varargout = untitled(varargin) ?
Sanjay Tiwari
Sanjay Tiwari el 7 de Ag. de 2019
The last line is error which compiler was showing and it is" function varargout=untitled(varargin)". As said earlier i am unable to define the varargout.
Walter Roberson
Walter Roberson el 7 de Ag. de 2019
You cannot define functions at the command line. You would need to store the above code in untitled.m
agreed to your point.but if i will create the varargout function what should be the code
is it like this
function varargout = untitled(varargin)
disp([' ' ]) % i dont know what to feed here
disp([''])% etc
for () = 1:nargout
varargout{k} = k;
end
end
it this is wrong what could be if you can help me in this code
for k = 1:nargout
varargout{k} = k;
end
disp([' ' ]) % i dont know what to feed here
disp([''])% etc
What did you want to output?

Iniciar sesión para comentar.

Respuestas (1)

Steven Lord
Steven Lord el 7 de Ag. de 2019

0 votos

It looks like you're trying to copy and paste that code into the Command Window. That's not going to work. As the error message states you will need to put that code in a file (as stated on this documentation page.) In this case, your file should end with the extension .m and its name needs to satisfy the same requirements as a valid variable name.
Once you've defined the function in the file and saved that file, call it.

5 comentarios

Thanks for the detailed response Steve. I slept at that time sorry for late response.
Well i have did the work again.
*********************************
function varargout = untitled(varargin)
for k = 1:nargout
varargout{k} = k;
end
end
**********
i saved this untitled.m (script) and then this programme (command wind)
**************************************
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if naragin && 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
handles.output = hObject;
guidata(hObject, handles);
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function dat_Callback(hObject, eventdata, handles)
function dat_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function CalcCRC_Callback(hObject, eventdata, handles)
data=get(handles.dat, 'String')
A = strread(data,'%u')
B=A'
Divisor=get(handles.divisor, 'String')
C= strread(Divisor,'%u')
D=C'
if (length(B)==7 && length(D)==5)
crc=mycrc(B,D,1)
crc result=[B,crc]
set(handles.reslt,'String',...
num2str(result))
set(handles.InfoBox,'String',...
['Result : ',...
num2str(result),' '])
else
set(handles.InfoBox,'String',...
['Data should be of 7 bits & divisor should be of 5 bits'])
end
function reslt_Callback(hObject, eventdata, handles)
% hObject handle to reslt (see GCBO)
function reslt_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function VerifCRC_Callback(hObject, eventdata, handles)
data=get(handles.reslt, 'String'
A = strread(data,'%u')
B=A'
Divisor=get(handles.divisor, 'String')
C= strread(Divisor,'%u')
D=C'
check=mycrc(B,D,2)
if check==[1]
set(handles.InfoBox,'String',...
[get(handles.InfoBox,'String'),...
'CRC check successful '])
end
if check~=[1]
set(handles.InfoBox,'String',...
[get(handles.InfoBox,'String'),...
'CRC check failed,data got corrupt on the way']
end
function InfoBox_ButtonDownFcn(hObject, eventdata, handles)
function RandmDatGen_Callback(hObject, eventdata, handles)
R = rand(1,7)
Y = round(R)
set(handles.dat, 'String',...
num2str(Y))
function divisor_Callback(hObject, eventdata, handles)
function divisor_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
******************************
error:
narargin not defined .
what is next ?????
I think that i could not clearly define my untitled script as well.
The code that you originally posted, the one that started with
function varargout = untitled(varargin)
What difficulty did you have when you stored that exact code in untitled.m ?
"narargin not defined ."
narargin is a mis-spelling of nargin .
However, nargin is only defined inside of functions, never in the command window. You should not be pasting any of that into the command window.
Sanjay Tiwari
Sanjay Tiwari el 12 de Ag. de 2019
Can you please help me with nargin function for this programme.
I tried to run with correct spelling and srcipt but i could not land on to somthing runing.
More over is untitled function is fine because compiler started with the first error or nargin i dont know when it will reach varargout.
Show the full and exact text of the error message (include all the text displayed in red) and show the line on which the error occurs in your function (with four or five lines before and after that line, for context.) If the error occurs on line 10 of your function, for example, show us lines 5 through 15 using:
dbtype 5:15 untitled.m
Adjust the "5:15" part to reflect the actual line number from the error.
Walter Roberson
Walter Roberson el 12 de Ag. de 2019
Please attach your current code and your .fig . Please do not post an image of code: attach the actual .m file
Please post a complete error message, together with a description of the actions needed to trigger the error.

Iniciar sesión para comentar.

Categorías

Más información sobre Argument Definitions en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Ag. de 2019

Comentada:

el 12 de Ag. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by