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:
Subtle Combination of Vectors

Subject: Subtle Combination of Vectors

From: smith Og

Date: 20 Aug, 2010 14:28:07

Message: 1 of 4

Hi,

I have vectors/scalars of x and y , and I want to combine them , I will give three examples. In any case, I want a combination of x and y.

example 1:
y = [y1 y2]
x = [x1 x2 x3]

Answer:
x1 y1
x2 y1
x3 y1
x1 y2
x2 y2
x3 y2

example 2:
y = y1
x = [x1 x2 x3]

Answer:
x1 y1
x2 y1
x3 y3

example 3:
y = [y1 y2 y3]
x = [x1 x2 x3]

Answer:
x1 y1
x2 y1
x3 y1
x1 y2
x2 y2
x3 y2
x1 y3
x2 y3
x3 y3

Note that x,and y can have any number of vectors. I have tried using built in function but no success. Any hint is okay.

Subject: Subtle Combination of Vectors

From: Steven_Lord

Date: 20 Aug, 2010 14:31:34

Message: 2 of 4



"smith Og" <adeog@ymail.com> wrote in message
news:i4m3dn$8rq$1@fred.mathworks.com...
> Hi,
> I have vectors/scalars of x and y , and I want to combine them , I will
> give three examples. In any case, I want a combination of x and y.
>
> example 1:
> y = [y1 y2]
> x = [x1 x2 x3]
>
> Answer:
> x1 y1
> x2 y1
> x3 y1
> x1 y2 x2 y2
> x3 y2
>
> example 2:
> y = y1
> x = [x1 x2 x3]
>
> Answer:
> x1 y1
> x2 y1
> x3 y3

Assuming the last line contains a typo, look at MESHGRID and NDGRID.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Subtle Combination of Vectors

From: Sean

Date: 20 Aug, 2010 14:37:04

Message: 3 of 4

"smith Og" <adeog@ymail.com> wrote in message <i4m3dn$8rq$1@fred.mathworks.com>...
> Hi,
>
> I have vectors/scalars of x and y , and I want to combine them , I will give three examples. In any case, I want a combination of x and y.
>
> example 1:
> y = [y1 y2]
> x = [x1 x2 x3]
>
> Answer:
> x1 y1
> x2 y1
> x3 y1
> x1 y2
> x2 y2
> x3 y2
>
> example 2:
> y = y1
> x = [x1 x2 x3]
>
> Answer:
> x1 y1
> x2 y1
> x3 y3
>
> example 3:
> y = [y1 y2 y3]
> x = [x1 x2 x3]
>
> Answer:
> x1 y1
> x2 y1
> x3 y1
> x1 y2
> x2 y2
> x3 y2
> x1 y3
> x2 y3
> x3 y3
>
> Note that x,and y can have any number of vectors. I have tried using built in function but no success. Any hint is okay.

You mean this:
[xx yy ]= meshgrid(1:3,4:6)
[xx(:),yy(:)]

Subject: Subtle Combination of Vectors

From: smith Og

Date: 20 Aug, 2010 14:44:05

Message: 4 of 4

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i4m3ug$d9h$1@fred.mathworks.com>...
> "smith Og" <adeog@ymail.com> wrote in message <i4m3dn$8rq$1@fred.mathworks.com>...
> > Hi,
> >
> > I have vectors/scalars of x and y , and I want to combine them , I will give three examples. In any case, I want a combination of x and y.
> >
> > example 1:
> > y = [y1 y2]
> > x = [x1 x2 x3]
> >
> > Answer:
> > x1 y1
> > x2 y1
> > x3 y1
> > x1 y2
> > x2 y2
> > x3 y2
> >
> > example 2:
> > y = y1
> > x = [x1 x2 x3]
> >
> > Answer:
> > x1 y1
> > x2 y1
> > x3 y3
> >
> > example 3:
> > y = [y1 y2 y3]
> > x = [x1 x2 x3]
> >
> > Answer:
> > x1 y1
> > x2 y1
> > x3 y1
> > x1 y2
> > x2 y2
> > x3 y2
> > x1 y3
> > x2 y3
> > x3 y3
> >
> > Note that x,and y can have any number of vectors. I have tried using built in function but no success. Any hint is okay.
>
> You mean this:
> [xx yy ]= meshgrid(1:3,4:6)
> [xx(:),yy(:)]

Very correct.

Thanks Sean, Steven

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