Indexing in fields of a struct

6 ビュー (過去 30 日間)
waqas
waqas 2020 年 8 月 7 日
コメント済み: waqas 2020 年 8 月 8 日
Hi, in the attached .MAT file, I have a struct partitionsInfo in which I want to read partitionsInfo.frames using indexing to find which section includes a particular number. For example partitionsInfo(1).frames contains number 1 as well as partitionsInfo(2).frames. Loops are not what I am looking for as currently I am working on test data and final data will be quite large already.
Another case would be where one particular number, say 4, is a part of 3 partitionsInfo.frames so the solution should give index for those 3 rows and for the test of the rows give zeros.
--Waqas

採用された回答

James Tursa
James Tursa 2020 年 8 月 7 日
編集済み: James Tursa 2020 年 8 月 7 日
Loops are what is needed here, but you can hide the loops behind function calls if you want. E.g.,
k = 3; % the number you are trying to find
x = arrayfun(@(i)any(partitionsInfo(i).frames==k),1:numel(partitionsInfo)); % logical indexes of elements you want
result = partitionsInfo(x);
  1 件のコメント
waqas
waqas 2020 年 8 月 8 日
I was actually trying something similar initially with structfun but was unsucessful. Thank you for the eligant solution.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by