Composing arrayfun syntax to extract data from structure
Mostra commenti meno recenti
Here is a simplified example of structure:
C(1,1).idx = [1;1;2;3];
C(2,1).idx = [1;1;2];
C(1,1).s = {'a';'a';'ab';'abc'};
C(2,1).s = {'a';'a';'ab'};
now, find unique idx in structure C:
[ua,ia,~] = arrayfun(@(x) unique(x.idx, 'rows'), C, 'UniformOutput', false);
How do I apply indexes ia to extract corresponding values in s fields? I can think of for loop but is there some arrayfun trick? Side note, in my real data idx is nx4 matrix therefore 'rows' argument.
5 Commenti
Azzi Abdelmalek
il 13 Nov 2012
It's not clear for me
Sean de Wolski
il 13 Nov 2012
+1 to Matt Fig's comment.
Milos
il 13 Nov 2012
Milos
il 13 Nov 2012
Risposta accettata
Più risposte (1)
Walter Roberson
il 13 Nov 2012
arrayfun(@(rowidx,idx) C(rowidx).s(idx{1}), 1:size(C,1), ia, 'UniformOutput', false)
or perhaps this might work:
arrayfun( @(idx, s) s{idx{1}}, ia, {C.s}, 'UniformOutput', false)
Categorie
Scopri di più su Time Series Objects in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!