Split vector into smaller vectors, then separate

I have a 240x1 cell, in each row there is a 1x1 struct. In each struct there are 5 fields, one of these is 'name' that can be target, notTarget, gap (these are the 3 possible names). The order is always the same (as concerning the name field): target or not target gap target or not target gap ....
I should split this vector in smaller vectors (2x1) made with a target (or not target) and a gap. Then I should separate the two different group of vectors: one with target, one with notTarget. Can anyone help me please?

2 件のコメント

Stephen23
Stephen23 2016 年 2 月 8 日
編集済み: Stephen23 2016 年 2 月 8 日
I would suggest that you convert your data in a non-scalar structure, then your task become easier using basic indexing and commands. The best solution would be to get rid of the cell array entirely, and have just one non-scalar structure. This will simplify your code and make is more efficient.
Bartolomeo Ruotolo
Bartolomeo Ruotolo 2016 年 2 月 9 日
Thank you very much!

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

 採用された回答

Guillaume
Guillaume 2016 年 2 月 8 日

0 投票

As per Stephen's comment, convert your cell array into a non-scalar structure (it should use more or less the same amount of memory:
c = {struct('name', 'target', 'idx', 1);
struct('name', 'not target', 'idx', 2);
struct('name', 'target', 'idx', 3)}; %for example
%convert c into non-scalar structure
ns = vertcat(c{:}); %concatenate all the structures into one.
If you want to split the non-scalar structure into two structures, it's dead easy:
targets = ns(strcmp({ns.name}, 'target'));
nottargets = ns(strcmp({ns.name}, 'not target'));

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeVariable Initialization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by