A simple Calculator

This is a simple calculator app built in MATLAB using the uicontrol GUI components. It runs in a pop-out figure window.
24 Downloads
Updated 13 Apr 2025

View License

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
  1. Run the script in MATLAB. A new window titled "Calculator" will open.
  2. Click number buttons (e.g., 1, 2, ., etc.) to build the first number.
  3. Click an operator (+, -, *, or /) to store that operation.
  4. Click the second number, then press = to evaluate.
  5. Press C to clear the current entry.
  6. 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 (2026). A simple Calculator (https://in.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 Linux
Version Published Release Notes
1.0.0