1

I asked this question last time. Answers there were very helpful. I want to suggest a slight variant. I need to access that element of a struct array which has a(i).x==5.65 && a(i).y==32.23?

Again i can run the good old for loop and find the index of required element but i have to make such queries multiple time. What is the fastest data structure to do this? What method should i use to search through the struct array to find the desired element?

Community
  • 1
  • 1
user_1_1_1
  • 903
  • 1
  • 12
  • 27

1 Answers1

2

You can use dot indexing to yield a comma-separated list and then coerce that into an array. You can then perform logical operations on the resulting array to yield a logical array that you can use to then index into your struct array

b = a([a.x] == 5 & [a.y] == 32)
Suever
  • 64,497
  • 14
  • 82
  • 101