Modify cell value of a row based on other cell value in same row uitable

2 visualizaciones (últimos 30 días)
Hi,
function uitable4_CellEditCallback(hObject, eventdata, handles)
a=get(handles.uitable4,'Data');
a = cell2table(a);
a.a6 = (10 / a.a5)*1^4; %where a.a6 is the column to be auto modify after editing column a.a5
a = table2cell(a);
set(handles.uitable4, 'Data',a);
Practically, I want every time I modify the value in a cell from a.a5 column, the a.a6 to be modified automaticaly, for the first row it's working but when I add another row i get the error:
To assign to or create a variable in a table, the number of rows must match the height of the table.
Practically, I unerstand the error but how to make the code working for every row? Thanks!
  11 comentarios
Simon Chan
Simon Chan el 8 de Jun. de 2022
Editada: Simon Chan el 8 de Jun. de 2022
This is another issue, you need to make uitable editable as follows:
Assume your uitable have 6 columns and if you would like to allow user to edit column 5 only, do the following.
uitable4.ColumnEditable=[false,false,false,false,true,false]
OR only update column 6 when column 5 is being edited.
function uitable4_CellEditCallback(hObject, eventdata, handles)
% Get the row number of your edited cell
rownum = eventdata.Indices(1);
colnum = eventdata.Indices(2);
% Update column 6 when column 5 has a new value
if isequal(colnum,5)
hObject.Data(rownum,6)=hObject.Data(rownum,colnum)+1000; % Add 1000 to the new value
end
end
Cristian Martin
Cristian Martin el 8 de Jun. de 2022
if colnum == 5;
hObject.Data{rownum,6}=hObject.Data{rownum,colnum}+1000; % Add 1000 to the new value
end
that resolve the problem
Thanks @Simon Chan for your patience, and answers !

Iniciar sesión para comentar.

Respuesta aceptada

Simon Chan
Simon Chan el 8 de Jun. de 2022
Just move the last comment as an answer.
function uitable4_CellEditCallback(hObject, eventdata, handles)
% Get the row number of your edited cell
rownum = eventdata.Indices(1);
colnum = eventdata.Indices(2);
% Update column 6 when column 5 has a new value
if isequal(colnum,5)
hObject.Data(rownum,6)=hObject.Data(rownum,colnum)+1000; % Add 1000 to the new value
end
end
Please accept the answer if it is useful for you.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Productos


Versión

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by