Find with an indexed struc

3 vues (au cours des 30 derniers jours)
AwedBy Matlab
AwedBy Matlab le 31 Juil 2014
Commenté : AwedBy Matlab le 1 Août 2014
I have a struc M whose size is (88,1)
If for instance I type M(46,1).acc I get ans = 0
I typed find(M(:,1).acc==0) to find the rows where the acc field is zero, but got the error Error using == : Too many input arguments.
Any help? Thanks!!

Réponse acceptée

Image Analyst
Image Analyst le 31 Juil 2014
Try
find([M(:,1).acc]==0)
  1 commentaire
AwedBy Matlab
AwedBy Matlab le 31 Juil 2014
Thanks!

Connectez-vous pour commenter.

Plus de réponses (1)

Ben11
Ben11 le 31 Juil 2014
Modifié(e) : Ben11 le 31 Juil 2014
It might not be the most elegant but I think it would solve your problem
Indices = cellfun(@(x) x == 0,struct2cell(M)) % you get a logical array where 0's have an index of 1
there is probably a more clever way to do it though.
  3 commentaires
Ben11
Ben11 le 31 Juil 2014
You're welcome! I prefer Image Analyst's answer though :)
AwedBy Matlab
AwedBy Matlab le 1 Août 2014
me too in this case :p

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by