Updated 2 Mar 2005
CREATABLE.M, WINDOWCLICK.M, EDITABLE.M
This is an example to show how an editable table can be created without using MATLAB's edit uicontrol. It has the advantage that you have more control over how key presses and mouse clicks are handled. You can limit the user input to certain characters, control the behaviour of arrow keys, etc..
In this example a table with numeric values is created in the current axis using CREATABLE.M. CREATABLE(NR,NC) creates a table with NR rows and NC columns filled with zeros. CREATABLE(DATA) creates a table with the same size as the DATA matrix and filled with the values of DATA.
WINDOWCLICK.M handles mouse button clicks inside the table (to start editing) and outside the table (to stop editing). It is also called by certain key presses that have the same effect as a mouse button click (arrow keys, enter, escape).
EDITABLE.M handles keyboard presses. Once a certain table cell has been clicked, any valid numeric character (including '+', '-', '.' and 'e') can be typed.
Furthermore, 'delete' empties the cell contents, 'backspace' removes the right-most character, 'arrow keys' move to another cell, 'enter' reselects the current cell, 'escape' (or clicking with the mouse outside the table) stops editing. The DATA is stored in the userdata of the current axes, thus at any time
during or after editing: DATA = GET(GCA,'USERDATA'). If a table cell contains an invalid number, NaN is returned for that cell.
These functions do not form a ready-to-use uicontrol. They are meant to be adapted for your own needs. Therefore, the functions have been kept as short as possible and no error checking (e.g. on typing beyond the cell width) is performed. The functions have been developed with MATLAB 7.0 (R14) and have also been tested with MATLAB 6.1 (R12).
Peter Graat (2023). editable table (https://www.mathworks.com/matlabcentral/fileexchange/7026-editable-table), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
- MATLAB > Language Fundamentals > Data Types > Tables >
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.