Deleting fields of a particular dimension in a structure
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Stephen23
2023 年 1 月 25 日
編集済み: Stephen23
2023 年 1 月 25 日
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 件のコメント
Stephen23
2023 年 1 月 26 日
"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.
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!