Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Inverse array lookup ( find() )

Subject: Inverse array lookup ( find() )

From: Anders

Date: 28 Apr, 2009 08:03:05

Message: 1 of 2

I have a 72x2x64 array where the cells represent: radius x [x y] x angle. Meaning, I have datapoints for 64 angles, 72 radius's and eachdata point consists of a x and y coordinate.
Now, I want to be able to query a pair of coordinates, and get all the angles and radius's which matches a pair of (x, y).

I tried something like this: indices = find(data(:,1,:) == x & data(:,2,:) == y); but it only returns the element index in the matrix (like [4057, 4058, 5678, 5679]), and not something like: (angel = [34, 42], radius = [2, 55]) which is what i want.

I hope you understand.

Also, It is possible for me to change data representation if you have a good idea, I'm not bound to this 72x2x64 matrix

Subject: Inverse array lookup ( find() )

From: Roger Stafford

Date: 28 Apr, 2009 16:20:17

Message: 2 of 2

Anders <vebihl@gmail.com> wrote in message <32576327.29258.1240905816232.JavaMail.jakarta@nitrogen.mathforum.org>...
> I have a 72x2x64 array where the cells represent: radius x [x y] x angle. Meaning, I have datapoints for 64 angles, 72 radius's and eachdata point consists of a x and y coordinate.
> Now, I want to be able to query a pair of coordinates, and get all the angles and radius's which matches a pair of (x, y).
>
> I tried something like this: indices = find(data(:,1,:) == x & data(:,2,:) == y); but it only returns the element index in the matrix (like [4057, 4058, 5678, 5679]), and not something like: (angel = [34, 42], radius = [2, 55]) which is what i want.
-------
  Though I am unable to try it out directly, I think that matlab will regard the expression

 data(:,1,:)==x&data(:,2,:)==y

where x and y are scalars, as a two-dimensional matrix of logical elements, in which case you can use the two-output-argument form of 'find'

 [I,K] = find(data(:,1,:)==x&data(:,2,:)==y);

I and K would then contain the desired subscripts into the corresponding radii and angles.

  If that doesn't work, you can use ind2sub appropriately to make the necessary conversion to these subscripts.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us