Deleting fields of a particular dimension in a structure
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have a struct with ints in it. I want to delete the fields with 1X13 int32 in it. Also, I would like to know the count of different fields with respect to its dimension. For example:- 120 fields with dimension int 1X12800.
0 Commenti
Risposte (1)
Stephen23
il 25 Gen 2023
Modificato: Stephen23
il 25 Gen 2023
As I wrote in several of your earlier questions, this task would be much easier if your data were better designed:
But lets try your preferred complex aproach. First some fake data:
S = struct('A',rand(1,12800),'B',rand(1,13),'C',rand(1,12800),'D',rand(1,13),'E',rand(1,23))
C = struct2cell(S);
F = @(a)isequal(size(a),[1,13]);
X = cellfun(F,C,'uni',1);
B = fieldnames(S);
Z = cell2struct(C(~X),B(~X),1)
This would be much easier using some kind of indexed array class, rather than forcing pseudo-indices into fieldnames.
"For example:- 120 fields with dimension int 1X12800."
V = cellfun(@(a)size(a,2),C);
U = unique(V)
N = histcounts(V,[U;Inf])
3 Commenti
Stephen23
il 26 Gen 2023
"When I run the command given in the previous answers by you, I run into the following error:"
I cannot debug code that you do not show here.
Providing the complete error message is also a requirement, if you want further help.
"How do I delete say the fields with dimensions 1X13?"
That is what my answer does. Take a look at my answer.
Vedere anche
Categorie
Scopri di più su Structures in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!