A simple Calculator
版本 1.0.0 (14.6 KB) 作者:
Stephen Wilkerson
This is a simple calculator app built in MATLAB using the uicontrol GUI components. It runs in a pop-out figure window.
Simple MATLAB Calculator GUI
Description
This is a simple calculator app built in MATLAB using the uicontrol GUI components. It runs in a pop-out figure window and mimics the functionality of a basic calculator. The purpose of this project is to help learners understand how to create interactive graphical interfaces in MATLAB with buttons, callbacks, and persistent state handling.
This calculator can:
- Perform basic arithmetic operations (+, -, *, /)
- Handle decimal number inputs
- Display results using a numeric label
- Include utility functions like clear (C) and exit (E)
The app was developed using a modular approach, with button generation and callback handling stored in functions for clean organization and extensibility.How to Use
- Run the script in MATLAB. A new window titled "Calculator" will open.
- Click number buttons (e.g., 1, 2, ., etc.) to build the first number.
- Click an operator (+, -, *, or /) to store that operation.
- Click the second number, then press = to evaluate.
- Press C to clear the current entry.
- Press E to exit the app.
For example:
- Click: 1 → . → 5 → + → 2 → =Output: 3.5
The label at the top updates live with either the number you're entering or the result of the operation.Code Structure
- createNumberButtons(f)Generates all calculator buttons dynamically using a nested loop. Assigns appropriate callbacks for each key.
- handleCalculatorInput(f, key)Handles user interaction. Tracks inputs, performs operations, and updates the GUI label.
- f.UserDataUsed to store the calculator's internal state (currentInput, firstNumber, operation, and label handle) across button presses.
Requirements
- MATLAB R2018b or later (due to use of anonymous functions and UserData)
- No additional toolboxes required
Screenshots
(Consider including a screenshot of the calculator GUI here on File Exchange.)
References
- Core logic and GUI design implemented collaboratively with ChatGPT by OpenAI, April 2025.
- MATLAB Documentation – uicontrol, UserData
- Special thanks to Stephen Wilkerson for project concept, implementation, and packaging for educational purposes.
引用格式
Stephen Wilkerson (2025). A simple Calculator (https://www.mathworks.com/matlabcentral/fileexchange/180782-a-simple-calculator), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
创建方式
R2024b
兼容任何版本
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.0.0 |