Skip to content
Menu
Barely Walking
  • Home
  • Robotics
  • SD, LLMs
  • One shot projects
  • 3d printers
  • About me
Barely Walking
07/10/201916/04/2022

Functions and figures in Matlab

This is a funny one – how to make a Matlab figure do some stuff on-demand with key presses and GUI elements.

Doing stuff in the background while the main script is running is a bit tricky in Matlab, but there is one thing that comes to your rescue: figures. Not only they allow you to display stuff, but they also provide a basic set of UI widgets and can call functions on demand. Want a simple example?

a = figure;
a.KeyPressFcn = @handleKeyPress;

function handleKeyPress(src,event)
    fprintf( "Someone pressed: %s\n", event.Key )
end

©2025 Barely Walking | Powered by WordPress and Superb Themes!