Find length of a structure element and remove them according to length?
2 ビュー (過去 30 日間)
古いコメントを表示
If I have a structure "output" with a field "output.I".
How can I check the lengths of all the output(1:end).I in one go and then remove the those rows from the structure that I do not require.
For example
output(1).I has a length of 100X1
output(2).I has a length of 200X1
output(3).I has a length of 100X1
I want to remove output(2).I = [] and my final structure to only have output(1).I and output(3).I
Please advise.
2 件のコメント
Rik
2018 年 3 月 26 日
Do you want to remove the structure element, or just empty out the field? The latter can be easily solved with a loop (and there may be several methods to do it faster), while the first is quite tricky (and will cause your elements to be renumbered).
採用された回答
Jos (10584)
2018 年 3 月 27 日
L = arrayfun(@(k) numel(output(k).I), 1:numel(output))
output(L > 100) = [] ; % remove those elements of the structure array
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!