A simple Calculator
Version 1.0.0 (14.6 KB) by
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.
Cite As
Stephen Wilkerson (2025). A simple Calculator (https://www.mathworks.com/matlabcentral/fileexchange/180782-a-simple-calculator), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2024b
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0 |