文章目录
0.Read me
This blog mainly gives an overview of how to use matlab to make a suggested calculator and implement its external layout. In this article, we use the Editor functional zone to realize the front-end layout. Details of each step and code explanation are included in the following introduction.
1.Basic Information
The Link Your Class | https://bbs.csdn.net/forums/ssynkqtd-04 |
---|---|
The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/617332156 |
The Aim of This Assignment | Visual calculator |
MU STU ID and FZU STU ID | 21125333(MU)/832101310(FZU) |
The link of the finished project code: https://github.com/E0000000/Calc1.0.git
2.PSP table
Personal Software Process Stages | Estimated Time(minutes) | Actual Time(minutes) |
---|---|---|
Planning | 50 | 45 |
• Estimate | 50 | 45 |
Development | 305 | 355 |
• Analysis | 25 | 25 |
• Design Spec | 30 | 20 |
• Design Review | 25 | 40 |
• Coding Standard | 50 | 65 |
• Design | 40 | 45 |
• Coding | 80 | 90 |
• Code Review | 40 | 35 |
• Test | 15 | 35 |
Reporting | 210 | 225 |
• Test Repor | 90 | 105 |
• Size Measurement | 60 | 65 |
• Postmortem & Process Improvement Plan | 60 | 55 |
Sum | 565 | 625 |
3.Description of problem-solving ideas
In this project, I first think about how to build the front-end visual interface. After the completion of the interface construction, I think about how to combine the back-end code with the front-end keys and achieve functions.
To find the information I need, I browse the CSDN and find many ways to realize the visual calculator. I tried python and AppInventor to make this calculator(will show in other blog which appended at the end of the article). But finally I choose Matlab cause I think it’s a much clearly way for me to acheive this work.
·Design and Implementation process
1.Determine the needs: First of all, we need to clarify the calculator functions that need to be designed. For basic calculators, we only need to design simple addition, subtraction, multiplication and division, delete keys, equal keys, and carry out a simple addition and subtraction operation sequence.
2.Interface layout: In the front-end page layout, we need to determine the size and place of each key, at the same time, we must divide the number key and the symbol key into two parts, so that the number key is placed together, and the symbol key is put together, so that the user can better adapt.
3.Add components: Place each button in the appropriate position and modify the parameters.
First, we enter ‘guide’ in the command bar:
Second, we drag the cell box on the left to the blank space on the right as needed:
Third, you can rename and change the parameters about the button:
Finally, we get the finished visual interface:
4.Result display
5.Code Section:
function varargout = calc(varargin)
% CALC MATLAB code for calc.fig
% CALC, by itself, creates a new CALC or raises the existing
% singleton*.
%
% H = CALC returns the handle to a new CALC or the handle to
% the existing singleton*.
%
% CALC('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CALC.M with the given input arguments.
%
% CALC('Property','Value',...) creates a new CALC or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before calc_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to calc_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
% Edit the above text to modify the response to help calc
% Last Modified by GUIDE v2.5 09-Oct-2023 23:03:19
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @calc_OpeningFcn, ...
'gui_OutputFcn', @calc_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 calc is made visible.
function calc_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 data (see GUIDATA)
% varargin command line arguments to calc (see VARARGIN)
% Choose default command line output for calc
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes calc wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = calc_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 data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.edit1,'string',[]);%clear
% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton14 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
set(handles.edit1,'string',num2str(eval(s0)));%find the final value
% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
% --- Executes on button press in pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton16 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
% --- Executes on button press in pushbutton17.
function pushbutton17_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton17 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
% --- Executes on button press in pushbutton18.
function pushbutton18_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton18 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
% --- Executes on button press in pushbutton19.
function pushbutton19_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton19 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
% --- Executes on button press in pushbutton20.
function pushbutton20_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton20 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
% --- Executes on button press in pushbutton21.
function pushbutton21_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton21 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
% --- Executes on button press in pushbutton22.
function pushbutton22_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton22 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
·code annotation
This code is divided into three simple parts and repeated many times. It is the number and the code of addition, subtraction, multiplication and division, the code of equal sign, and the code of delete key.For the three parts, the callback function is used.
The first part:
s0=get(handles.edit1,'string');
s=get(hObject,'string');
set(handles.edit1,'string',[s0,s]);
The second part:
s0=get(handles.edit1,'string');
set(handles.edit1,'string',num2str(eval(s0)));%find the final value
The third part:
set(handles.edit1,'string',[]);%clear
6.Summary
This is the first time to design a visual calculator, I learned a lot about the way of front-end construction, and finally chose matlab to implement the code and front-end together, but this calculator can only carry out four simple operations, and still does not have trigonometric functions and other computing functions, I hope to improve in the future
7.Link
Link: how to use AppInventor to make a calculator:http://t.csdnimg.cn/UjvjI