App designer editable table input first character incorrect?

3 Ansichten (letzte 30 Tage)
David Spelman
David Spelman am 9 Aug. 2019
Beantwortet: Deepak am 3 Jun. 2025
Within an app I have an editable table in which a user can input the values of a matrix. If the user attempts to enter a negative number, the minus sign enters as an "m" character if it is the first keystroke. For any further keystrokes, the minus sign is entered correctly. An idea what's happening here?

Antworten (1)

Deepak
Deepak am 3 Jun. 2025
In MATLAB R2018a, a known issue affects editable "UITable" components in App Designer where typing a minus sign (-) as the first character sometimes results in an "m" being entered instead. This occurs due to how the UI processes initial keystrokes and can prevent users from inputting negative numbers correctly.
We can resolve this by using the "CellEditCallback" to detect and correct such input. The callback checks if the new value contains an incorrect "m" character and replaces it with a minus sign before converting it to a number.
Below is a sample MATLAB code to implement this:
function UITable_CellEditCallback(app, event)
row = event.Indices(1);
col = event.Indices(2);
newData = event.NewData;
% Replace 'm' with '-' and convert to number
fixedData = str2double(strrep(char(newData), 'm', '-'));
if isnan(fixedData)
uialert(app.UIFigure, 'Invalid input. Please enter a number.', 'Input Error');
else
app.UITable.Data{row, col} = fixedData;
end
end
Please find attached the documentation of Table UI component for reference:
I hope this helps.

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by