How to pick out rows from a 2D cell array based on several criteria
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a 2D cell array. The first column is a string, the columns 3:5 are x, y, z coordinates, and the remaining columns are data. I need to be able to pick out the rows that match a specified string and coordinates and put them into new array.
The only way I figured out how to do this is (in is the input array, name is the string I want to match, xyz are the coordinates.)
a=find(strcmp(in(:,1),name));
b=find(cell2mat(in(:,3))==x);
c=find(cell2mat(in(:,4))==y);
d=find(cell2mat(in(:,5))==z);
e=intersect(a,b);
f=intersect(c,d);
g=intersect(e,f);
out=in(g,:);
Seems pretty cumbersome, is there a better way to do this?
0 Commenti
Risposte (2)
Azzi Abdelmalek
il 19 Feb 2013
Modificato: Azzi Abdelmalek
il 19 Feb 2013
in={'a' [1] [2] [3] [100];'b' [11] [12] [13] [1000]}
x=1;y=2;z=3; % Your data
%-----------------------The code----------------------------------------
out=in(arrayfun(@(x) isequal(in{x,1},'a')& isequal(cell2mat(in(x,2:4)),[x y z]),[1:size(in,1)]'),:)
0 Commenti
Vedere anche
Categorie
Scopri di più su Operators and Elementary Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!