How to remove empty line from struct?
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello every one
I have struct D with two fields: index
sequence [ ]
D :
1 [1 2 4 5]
[] []
3 [1 2 4 5]
4 [1 2 3 5]
I want to remove the empty line from D and become
1 [1 2 4 5]
3 [1 2 4 5]
4 [1 2 3 5]
thank you
0 comentarios
Respuestas (2)
Walter Roberson
el 16 de Mayo de 2023
mask = cellfun(@isempty, {D.index}) & cellfun(@isempty, {D.sequence});
D = D(~mask);
0 comentarios
Yazan
el 17 de Ag. de 2021
D.f1 = [1 2 3 4 5];
D.f2 = [];
% structure with 2 fields
D
% get fields
fields = fieldnames(D)
% remove empty fields
D = rmfield(D, fields(structfun(@isempty, D)))
4 comentarios
Tobias Wrammerfors
el 16 de Mayo de 2023
As far as I can tell, this seems to remove empty fields, not rows that are empty in all fields.
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!