agnieszka
agnieszka

Reputation: 15345

How to search array of structures in matlab?

I have an array of structures, each structure with fields 'input' and 'output'. Input values are binary arrays, output values are integers. Let's say I have a specific binary array, for example A = [0 1 1 0 1 0]. How do I find the element in my array that has value in input field equal to A?

Upvotes: 1

Views: 5005

Answers (1)

Jonas
Jonas

Reputation: 74940

You could use ARRAYFUN

logicalIndexOfElement = arrayfun(@(x)all(x.input==A),yourStructure)

Call FIND on logicalIndexOfElement to get the linear indices of the elements in yourStructure.

Upvotes: 8

Related Questions