how to resolve varagout error

3 views (last 30 days)
Sanjay Tiwari
Sanjay Tiwari on 6 Aug 2019
Commented: Walter Roberson on 12 Aug 2019
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 Comments
Sanjay Tiwari
Sanjay Tiwari on 7 Aug 2019
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
Walter Roberson
Walter Roberson on 7 Aug 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?

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 7 Aug 2019
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 Comments
Steven Lord
Steven Lord on 12 Aug 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
Walter Roberson on 12 Aug 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.

Sign in to comment.

Categories

Find more on Argument Definitions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!