How to pick out rows from a 2D cell array based on several criteria
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Azzi Abdelmalek
le 19 Fév 2013
Modifié(e) : Azzi Abdelmalek
le 19 Fév 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 commentaires
Voir également
Catégories
En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!