Is there any way to "clean" a single row of a uitable?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Pedro Guevara
le 2 Juil 2019
Commenté : Pedro Guevara
le 30 Juil 2019
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
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.
0 commentaires
Réponse acceptée
Adam Danz
le 2 Juil 2019
Modifié(e) : Adam Danz
le 2 Juil 2019
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);
19 commentaires
Adam Danz
le 27 Juil 2019
Modifié(e) : Adam Danz
le 27 Juil 2019
Pedro, here is the ENTIRE workflow. This is an independent, working example of every step from setting up the UI table, loading it with data, copying the data into a variable, removing a row, and updating the data in the UI table.
Go through every single line, one-by-one to understand what's going on and pay attention to the comments.
Before you apply this to your existing code, save a copy of your code because it works (remember, you're just unhappy with the NaNs which really don't cause any problem with the analysis).
% Create a matrix of NUMBERS
d = randi(10,3,3);
% Convert matrix of NUMBERS into cell array of CHARS
ds = compose('%d',d); %Requires r2016b
%ds = sprintfc('%d', d); % undocumented alternative
% Create a demp UITable
f = figure;
h = uitable('Position',[20 20 262 204]);
h.Data = ds; % IMPORT THE CELL ARRAY OF STRINGS AS DATA
% Copy current table to a local variable
t = get(h,'Data'); % <---- still a cell array of strings
% Identify which row numbers to clear
rowIdx = [1,2]; % Clear rows 1 and 2
% Clear those rows in the local variable
t(rowIdx,:) = {''};
% Reassign updated table to the GUI
set(h,'Data',t);
% Get a NEW copy of the current table
t2 = get(h,'Data'); % <---- still a cell array of strings
% Assign new data in the first row
newdata = [1,2,3]; % NUMERIC!
ds2 = compose('%d',newdata); % CELL OF STRINGS
t2(1,:) = ds2;
set(h,'Data',t2);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!