Effacer les filtres
Effacer les filtres

delete columns in a struct array

6 vues (au cours des 30 derniers jours)
pamela sulis
pamela sulis le 14 Mar 2016
Modifié(e) : Guillaume le 14 Mar 2016
Hi!
I have a struct array E struct, attached, and I want to delete the columns of each struct that correspond to []: example E(1,5).{1,1}, E(1,9).{1,1}. Can you help me? thanks

Réponse acceptée

Guillaume
Guillaume le 14 Mar 2016
Modifié(e) : Guillaume le 14 Mar 2016
"I want to delete the columns of each struct". No, you want to delete the columns of the cell array, if present, contained in the 'bcd' field of each struct. It's important to use proper terminology so you can be understood. It also helps in finding out how to solve the problem:
for siter = 1:numel(E) %iterate over each structure
c = E(siter).bcd; %get cell array in field 'bcd' of structure
if iscell(c) %some structures don't have a cell array in the field
emptycell = cellfun(@isempty, c); %find empty columns of cell array
c(emptycell) = []; %delete empty cell
E(siter).bcd = c; %and put back in structure field
end
end
Or in a more compact form (but slightly more difficult to understand
for siter = 1:numel(E)
if iscell(E(siter).bcd)
E(siter).bcd(cellfun(@isempty, E(siter).bcd)) = [];
end
end

Plus de réponses (0)

Catégories

En savoir plus sur Structures 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!

Translated by