App designer editable table input first character incorrect?
2 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
Deepak
2025-6-3
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!