App designer editable table input first character incorrect?

4 visualizaciones (últimos 30 días)
David Spelman
David Spelman el 9 de Ag. de 2019
Respondida: Deepak el 3 de Jun. de 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?

Respuestas (1)

Deepak
Deepak el 3 de Jun. de 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.

Categorías

Más información sobre Tables en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by