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:
Combining row vectors

Subject: Combining row vectors

From: Thijs

Date: 14 Jul, 2010 13:57:04

Message: 1 of 8

Hello,

I have a question regarding combining several different row vectors to make one large row vector. Using v3 = [v1, v2] is not an option in this case because I have about 100 vectors that I want to combine to one. Does anybody have a solution for combining a large amount (amount changes often) of vectors?

Thank you in advance.

Thijs

Subject: Combining row vectors

From: Sean

Date: 14 Jul, 2010 14:05:18

Message: 2 of 8

"Thijs " <t.denhamer@student.tudelft.nl> wrote in message <i1kfng$t87$1@fred.mathworks.com>...
> Hello,
>
> I have a question regarding combining several different row vectors to make one large row vector. Using v3 = [v1, v2] is not an option in this case because I have about 100 vectors that I want to combine to one. Does anybody have a solution for combining a large amount (amount changes often) of vectors?

%One way:
%Load you row vectors in as cells then use cell2mat
A{1} = rand(10,1);
A{2} = ones(14,1);
cell2mat(A.').'

Subject: Combining row vectors

From: Andy

Date: 14 Jul, 2010 14:09:05

Message: 3 of 8

"Thijs " <t.denhamer@student.tudelft.nl> wrote in message <i1kfng$t87$1@fred.mathworks.com>...
> Hello,
>
> I have a question regarding combining several different row vectors to make one large row vector. Using v3 = [v1, v2] is not an option in this case because I have about 100 vectors that I want to combine to one. Does anybody have a solution for combining a large amount (amount changes often) of vectors?
>
> Thank you in advance.
>
> Thijs

If you know that you'll be doing this later in the code, then you should collect these vectors together in, for example, a cell array as you create them. That way, when you want to concatenate all of them, you can use:

C = {v1 v2 v3 ...}; % your cell array of vectors;
V = [C{:}]; % concatenate all of them

Subject: Combining row vectors

From: James Tursa

Date: 14 Jul, 2010 14:10:32

Message: 4 of 8

"Thijs " <t.denhamer@student.tudelft.nl> wrote in message <i1kfng$t87$1@fred.mathworks.com>...
> Hello,
>
> I have a question regarding combining several different row vectors to make one large row vector. Using v3 = [v1, v2] is not an option in this case because I have about 100 vectors that I want to combine to one. Does anybody have a solution for combining a large amount (amount changes often) of vectors?

Do they all have different names? How are they created? Can you make them part of a large row vector as they are created?

James Tursa

Subject: Combining row vectors

From: us

Date: 14 Jul, 2010 14:11:05

Message: 5 of 8

"Thijs " <t.denhamer@student.tudelft.nl> wrote in message <i1kfng$t87$1@fred.mathworks.com>...
> Hello,
>
> I have a question regarding combining several different row vectors to make one large row vector. Using v3 = [v1, v2] is not an option in this case because I have about 100 vectors that I want to combine to one. Does anybody have a solution for combining a large amount (amount changes often) of vectors?
>
> Thank you in advance.
>
> Thijs

well...
an excellent example why any reasonable MLbber would NEVER create zillions of (enumerated) variables...

http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

a possible remedy:
- save your VARs in a temp MAT-file...
- reload the MAT-file into a STRUCT...
- use STRUCT2CELL to turn it into a ... CELL...
- use CAT to create an array...

us

Subject: Combining row vectors

From: Thijs

Date: 14 Jul, 2010 15:02:06

Message: 6 of 8

Dear James,

I am working on a packing problem in which objects are placed inside a large matrix. My program stores the linear indices of the cells in which by objects are placed. Because all of the objects are larger than one cell in the matrix, every object gets a number of indices assigned, thes indices are subsequently combined into a row vector.
All the vectors have the same name, but they are stored as a property of the object to which they belong.

Thijs

"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <i1kggo$lfd$1@fred.mathworks.com>...
> "Thijs " <t.denhamer@student.tudelft.nl> wrote in message <i1kfng$t87$1@fred.mathworks.com>...
> > Hello,
> >
> > I have a question regarding combining several different row vectors to make one large row vector. Using v3 = [v1, v2] is not an option in this case because I have about 100 vectors that I want to combine to one. Does anybody have a solution for combining a large amount (amount changes often) of vectors?
>
> Do they all have different names? How are they created? Can you make them part of a large row vector as they are created?
>
> James Tursa

Subject: Combining row vectors

From: James Tursa

Date: 14 Jul, 2010 15:23:04

Message: 7 of 8

"Thijs " <t.denhamer@student.tudelft.nl> wrote in message <i1kjhe$d92$1@fred.mathworks.com>...
> Dear James,
>
> I am working on a packing problem in which objects are placed inside a large matrix. My program stores the linear indices of the cells in which by objects are placed. Because all of the objects are larger than one cell in the matrix, every object gets a number of indices assigned, thes indices are subsequently combined into a row vector.
> All the vectors have the same name, but they are stored as a property of the object to which they belong.

Please be more specific. How, exactly, are the vectors stored? As separately named variables? As part of a cell array? As part of a structure? We can't really advise you until we know what you are doing.

James Tursa

Subject: Combining row vectors

From: Thijs

Date: 14 Jul, 2010 15:34:04

Message: 8 of 8

The vector is stored as a variable inside a structure. Each object has its own structure, because several other properties of the objects are also stored.

Thijs

"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <i1kkoo$542$1@fred.mathworks.com>...
> "Thijs " <t.denhamer@student.tudelft.nl> wrote in message <i1kjhe$d92$1@fred.mathworks.com>...
> > Dear James,
> >
> > I am working on a packing problem in which objects are placed inside a large matrix. My program stores the linear indices of the cells in which by objects are placed. Because all of the objects are larger than one cell in the matrix, every object gets a number of indices assigned, thes indices are subsequently combined into a row vector.
> > All the vectors have the same name, but they are stored as a property of the object to which they belong.
>
> Please be more specific. How, exactly, are the vectors stored? As separately named variables? As part of a cell array? As part of a structure? We can't really advise you until we know what you are doing.
>
> James Tursa

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