MATLAB Function에서 struct의 배열 별 요소 개수 구하기
4 ビュー (過去 30 日間)
古いコメントを表示
MATLAB Function에서 arr의 struct 배열 개수, 배열 별 요소의 개수를 구하고 출력하고 싶습니다.
배열 별 요소 개수를 구하기 위해 cell_num을 구현했는데 적절한가요? 또한, 출력하려면 어떻게 해야 하나요?
cell_num = struct();
arr = struct("sig1",{{1,2,3,4}},"sig2",{{4,5,6}},"sig3",{{7,8}});
sig_num = 3;
for i = 1:sig_num
cell_num = structfun(@size,arr,"UniformOutput",false);
y = cell_num(i);
end
0 件のコメント
採用された回答
Dyuman Joshi
2023 年 9 月 20 日
%Defining structure
cell_num = struct();
arr = struct("sig1",{{1,2,3,4}},"sig2",{{4,5,6}},"sig3",{{7,8}})
%Field names of the structure arr
names = fieldnames(arr)
%Number of fields in arr
n = numel(names)
%Number of elements in each field
y = structfun(@numel,arr)
To display or printf -
%Method 1
disp(y)
%Method 2
fprintf('%d\n',y)
2 件のコメント
Dyuman Joshi
2023 年 9 月 21 日
There is no need to use UniformOutput=false for the structfun command.
You can see that I have not used that in my code above.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で 멀티레이트 신호 처리 についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!