Creating a field to display/edit variable in the uitoolbar

6 views (last 30 days)
I have a GUI which displays Tables and Plots of numerous objects of my Data class one at a time. To navigate between the different samples (or objects) of my Data class, I have created navigation buttons using the uipushtool component and it works fine. Now, additionally I would like to add a component that displays the index of the sample (a 'numeric' variable) and possibly lets the user edit the index to navigate to that sample.
I thought of using the uispinner but that creates issues such as the maximum limit being the same as minimum limit at the time of construction, and the need to dynamically change the maximum limit based on the addition/deletion of Data samples.
Are there any possibilties to add this display/edit functionality in the MATLAB uitoolbar?

Answers (1)

Kanishk
Kanishk on 20 Dec 2024
From the documentation of 'uipushtool', only icons and images can be added to it. You can have UIControl objects like edit fields and spinners in the app itself to display to the index of the sample. Here is a simple example using MATLAB App Designer to display the index and edit it for navigation.
This can be achieved by adding a callback to the edit field UIControl as follows.
function EditFieldValueChanged(app, event)
if app.EditField.Value > 0 && app.EditField.Value <= size(app.dataObj, 2)
app.curIdx = app.EditField.Value;
else
app.EditField.Value = 1;
end
app.updateTable();
end
function updateTable(app)
app.UITable.Data = app.dataObj(app.curIdx).data;
app.EditField.Value = app.curIdx;
end
The "updateTable" updates the table with the current index everytime the function is called. The can be used in next and prev buttons after updating the index.
You can check out the documentation for edit field using the following command.
web(fullfile(docroot, 'matlab/ref/uieditfield.html'))
Thanks!!

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!