how to resolve varagout error
Mostrar comentarios más antiguos
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
el 6 de Ag. de 2019
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
el 7 de Ag. de 2019
David Goodmanson
el 7 de Ag. de 2019
Hi Sanjay, is that last line supposed to be just varargout = untitled(varargin) ?
Sanjay Tiwari
el 7 de Ag. de 2019
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
Sanjay Tiwari
el 7 de Ag. de 2019
Walter Roberson
el 7 de Ag. de 2019
for k = 1:nargout
varargout{k} = k;
end
disp([' ' ]) % i dont know what to feed here
disp([''])% etc
What did you want to output?
Respuestas (1)
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.
5 comentarios
Sanjay Tiwari
el 8 de Ag. de 2019
Walter Roberson
el 8 de Ag. de 2019
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
el 12 de Ag. de 2019
Steven Lord
el 12 de Ag. de 2019
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
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.
Categorías
Más información sobre Argument Definitions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!