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:
Using all elements in a matrix for calculation / Indexing Question

Subject: Using all elements in a matrix for calculation / Indexing Question

From: Felix

Date: 10 Jan, 2011 14:26:04

Message: 1 of 2

Dear all,

I have a matrix of size 200 X 2 consisting of some coordinates. I have an expression for which I need to use every single pair of elements possible (x,y) i.e. 40 000 different combinations.

Could someone please advise me how to set up the code whilst avoiding the use of for loops.

Thanks a lot,

FW

Subject: Using all elements in a matrix for calculation / Indexing Question

From: Sean de

Date: 10 Jan, 2011 14:37:04

Message: 2 of 2

"Felix" wrote in message <igf4ts$pej$1@fred.mathworks.com>...
> Dear all,
>
> I have a matrix of size 200 X 2 consisting of some coordinates. I have an expression for which I need to use every single pair of elements possible (x,y) i.e. 40 000 different combinations.
>
> Could someone please advise me how to set up the code whilst avoiding the use of for loops.
>
> Thanks a lot,
>
> FW

help meshgrid
[xx yy] = meshgrid(X(:,1),X(:,2));

then use sub2ind, to index
help sub2ind

Tags for 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