How to change value of specific uitable cell on MATLAB GUI?

11 views (last 30 days)
Good day! I am working on MATLAB GUI and I would like to ask how can I add change the numeric value (by adding/subtracting value) on a specific cell of uitable? Given that the entries shown on the uitable are called from an excel file, how can I change the value on a specific cell using a push button?
For an example:
The data is transferred from the excel file to uitable:
cell 1 value = '4', cell 2 value = '5'.
1st condition:
When push button 1 is pressed, it subtracts 1 from the cell values:
cell 1 value = '3', cell 2 value = '4'.
2nd condition:
When push button 2 is pressed, it adds 1 to the cell values:
cell 1 value = '5', cell 2 value = '6'.
Thank you so much.

Answers (1)

Walter Roberson
Walter Roberson on 31 Aug 2015
If you read in the files from the file as text, use str2double() to convert them to numeric form. Set the Data property of the uitable to be the numeric values. Suppose that table is handles.uitable1 then set(handles.uitable1, 'Data', TheValues)
If all of the cells of the uitable are to be numeric, then TheValues can be a numeric array instead of a cell array that includes scalar numeric values.
If you were able to use numeric arrays for the uitable, then when the first button is pushed,
data = get(handles.uitable1, 'Data');
data = data - 1;
set(handles.uitable1, 'Data', data);
otherwise
data = get(handles.uitable1, 'Data');
for K = 1 : 2
data{K} = data{K} - 1;
end
set(handles.uitable1, 'Data', data);
  6 Comments
Buddhini Angelika
Buddhini Angelika on 30 Dec 2015
Is there a way to make alterations to the contents of the cells of uitable from the interface, by manually typing on the cells?
Walter Roberson
Walter Roberson on 30 Dec 2015
Buddhini Angelika: Yes, if you set the ColumnEditable property to allow editing the content.

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!