📄 untitled.m
字号:
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -