Insert data in uitable from textbox
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi i’m working on program depends on inserting two numbers into two text boxes. When I press the pushbutton, the two numbers are combined and displayed in the first row of the table. When I enter two other numbers in the text boxes and press the pushbutton again, the new resolt is displayed in the second row of the table and etc. But the problem is that the new resolt replaces the old resolt in the first row What’s the code that allow me to set data in second row then thired etc....
0 Kommentare
Antworten (1)
Hitesh
am 30 Aug. 2024
Hi Abdullah,
The challenge you are facing arises when the new results are added to the table without preserving the existing data, resulting in the current content being overwritten. To address this, kindly ensure that you retrieve the current data from the table before incorporating any new entries.
For guidance on updating the table while maintaining the existing data, please refer to the documentation and code provided below.
% txt1 is the textfield1, txt2 is textfiled2 and tb1 is table
function onButtonPushed(txt1, txt2, tbl)
% Get the numbers from text boxes
num1 = txt1.Value;
num2 = txt2.Value;
% Combine the numbers as a string
combinedStr = sprintf('%d%d', num1, num2);
% Get the current row index from UserData
currentRow = tbl.UserData;
% Get current data from the table
currentData = tbl.Data;
% Ensure the table has enough rows
if size(currentData, 1) < currentRow
currentData{currentRow, 1} = combinedStr;
else
currentData{end+1, 1} = combinedStr;
end
% Update the table data
tbl.Data = currentData;
% Increment the row index for the next entry
tbl.UserData = currentRow + 1;
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!