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:
how to combine multiple variables into one

Subject: how to combine multiple variables into one

From: wei H

Date: 18 Nov, 2006 23:59:56

Message: 1 of 4

Hi,

Does anybody know whether Matlab can combine multiple variables into
one?

Suppose I have three vectors that look like this:

1 2 3
3 2 1
3 2 4
1 2 3
2 3 1

Now I want to combine these three vectors together into a single one
that look like this:

123
321
324
123
231

Can Matlab handle this situation? If so, what syntax should be used?

Thanks a lot!

Wei

Subject: how to combine multiple variables into one

From: Seyfullah Halit Oguz

Date: 19 Nov, 2006 05:16:23

Message: 2 of 4

wei H wrote:
>
>
> Hi,
>
> Does anybody know whether Matlab can combine multiple variables
> into
> one?
>
> Suppose I have three vectors that look like this:
>
> 1 2 3
> 3 2 1
> 3 2 4
> 1 2 3
> 2 3 1
>
> Now I want to combine these three vectors together into a single
> one
> that look like this:
>
> 123
> 321
> 324
> 123
> 231
>
> Can Matlab handle this situation? If so, what syntax should be
> used?
>
> Thanks a lot!
>
> Wei

Hi,

I am not exactly sure what you meant by 'combining ... into a single
one' (vector or matrix?) but here are some solutions:

Solution (I)
v1 = [1 3 3 1 2]';
v2 = [2 2 2 2 3]';
v3 = [3 1 4 3 1]';

v_single = [v1 v2 v3]; % a 5x3 matrix

Solution (II)
v1 = [1 3 3 1 2]';
v2 = [2 2 2 2 3]';
v3 = [3 1 4 3 1]';

v_single = sum(((10.^(kron(ones(size(v1)),[2:-1:0]))).*[v1 v2
v3])')'; % a 5x1 array

Best regards,
Seyfullah Halit Oguz

Subject: how to combine multiple variables into one

From: zia

Date: 19 Nov, 2006 02:34:18

Message: 3 of 4

Hello,
Here is how I would do it. Maybe there is a better way to do it.
x= [1 2 3
3 2 1
3 2 4
1 2 3
2 3 1 ];

a=num2str(x(:,1));
b=num2str(x(:,2));
c=num2str(x(:,3));

y=str2num([a,b,c])

I hope this helps,
-zia


wei H wrote:
> Hi,
>
> Does anybody know whether Matlab can combine multiple variables into
> one?
>
> Suppose I have three vectors that look like this:
>
> 1 2 3
> 3 2 1
> 3 2 4
> 1 2 3
> 2 3 1
>
> Now I want to combine these three vectors together into a single one
> that look like this:
>
> 123
> 321
> 324
> 123
> 231
>
> Can Matlab handle this situation? If so, what syntax should be used?
>
> Thanks a lot!
>
> Wei

Subject: how to combine multiple variables into one

From: Peter Boettcher

Date: 20 Nov, 2006 09:33:56

Message: 4 of 4

"wei H" <heweit@gmail.com> writes:

> Hi,
>
> Does anybody know whether Matlab can combine multiple variables into
> one?
>
> Suppose I have three vectors that look like this:
>
> 1 2 3
> 3 2 1
> 3 2 4
> 1 2 3
> 2 3 1
>
> Now I want to combine these three vectors together into a single one
> that look like this:
>
> 123
> 321
> 324
> 123
> 231
>
> Can Matlab handle this situation? If so, what syntax should be used?

Are both of those matrices supposed to be normal numbers (rather than
strings)? Then think about what the mathematical operation is. First
number times 100, plus second number times 10, plus third number. And
that is easily expressed in matrix notation:

A = [1 2 3; 3 2 1; 3 2 4; 1 2 3; 2 3 1];

B = A*[100; 10; 1];


--
Peter Boettcher <boettcher@ll.mit.edu>
MIT Lincoln Laboratory
MATLAB FAQ: http://www.mit.edu/~pwb/cssm/

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