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
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!