MATLAB: Is there any way to “clean” a single row of a uitable

celleditcallbackcleanconditionMATLABrowsuitable

Good day. I have the following problem I have a uitable to which some data must be entered. What I want is to clean a row where you are entering the data whenever a condition is fulfilled. Currently I have a line of code that allows me to clean all the contents of the table, but as I said, I just need to clean the row that meets the condition. Here I owe part of the code for your evaluation:
function TablaDatosElementos_CellEditCallback(hObject, eventdata, handles)
if ( ( datos ( V_org(celdas,1),7 ) == datos ( V_org(celdas,1),9 ) ) || ( datos ( V_org(celdas,1),6 ) == datos ( V_org(celdas,1),8 ) ) ) % Condition NOT TO BE FULFILLED TO CLEAN THE ROW.
else
set(handles.TablaDatosElementos, 'Data', cell(size(get(handles.TablaDatosElementos,'Data')))); % THIS IS THE CODE LINE THAT CLEAN ME ALL THE UITABLE.
end
end
tabla.JPG
I hope you can help me with this problem, since after a lot of research it seems that there is no way to do a selective cleaning of the uitable. Thank you.

Best Answer

To clear a list of rows from a table, copy the entire table into a local variable, empty the desired rows, and then reassign the local table back to the UI table.
% Create demo UItable
d = {'Male',52,9;'Male',40,0;'Female',25,9};
f = figure;
handles.TablaDatosElementos = uitable(f,'Data',d,'Position',[20 20 262 204]);
% 1) copy current table to a local variable
t = get(handles.TablaDatosElementos,'Data');
% 2) Identify which row numbers to clear
rowIdx = [1,2]; % Clear rows 1 and 2
% 3) Clear those rows in the local variable
t(rowIdx,:) = cell(numel(rowIdx),size(t,2));
% 4) reassign updated table to the GUI
set(handles.TablaDatosElementos,'Data',t);