Thread Subject: concatenation element by element

Subject: concatenation element by element

From: ventus85

Date: 19 Mar, 2010 17:25:23

Message: 1 of 4

Good morning.
I have:
a=[1,2;3,4]
b=[5,6;7,8]
I get as a result
c=[ [1,5] , [2,6] ; [3,7] , [4,8] ]
I enter in c(i,j) the item [a(i,j),b(i,j)] without cycle.

With
a=[1,2,3;0,3,2;6,7,1]
b=[4,6,2;1,1,3;3,2,5]
sizea=size(a);
for i=1:sizea(1)
    for j=1:sizea(2)
        c{i,j}=[{a(i,j)},{b(i,j)}]
    end
end

if I have large arrays of the program becomes very slow.

How can I do?

Thanks.

Subject: concatenation element by element

From: us

Date: 19 Mar, 2010 17:45:22

Message: 2 of 4

"ventus85 " <ventus85@katamail.com> wrote in message <ho0c23$88f$1@fred.mathworks.com>...
> Good morning.
> I have:
> a=[1,2;3,4]
> b=[5,6;7,8]
> I get as a result
> c=[ [1,5] , [2,6] ; [3,7] , [4,8] ]
> I enter in c(i,j) the item [a(i,j),b(i,j)] without cycle.
>
> With
> a=[1,2,3;0,3,2;6,7,1]
> b=[4,6,2;1,1,3;3,2,5]
> sizea=size(a);
> for i=1:sizea(1)
> for j=1:sizea(2)
> c{i,j}=[{a(i,j)},{b(i,j)}]
> end
> end
>
> if I have large arrays of the program becomes very slow.
>
> How can I do?
>
> Thanks.

a hint:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/276902

us

Subject: concatenation element by element

From: Matt J

Date: 19 Mar, 2010 17:54:05

Message: 3 of 4

"ventus85 " <ventus85@katamail.com> wrote in message <ho0c23$88f$1@fred.mathworks.com>...

> if I have large arrays of the program becomes very slow.
>
> How can I do?
>

If you have large arrays, it's a bad idea to begin with to load them into finely partitioned cell arrays. It's going to introduce a lot of unnecessary overhead when you manipulate the data as a cell instead of in the original matrix form of a and b.

Still, this might be better:

c= reshape( num2cell( [a(:),b(:)],2) , size(a))

Subject: concatenation element by element

From: ventus85

Date: 19 Mar, 2010 18:03:05

Message: 4 of 4

Perfect!
Thank you!

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <ho0dnt$6lg$1@fred.mathworks.com>...
> "ventus85 " <ventus85@katamail.com> wrote in message <ho0c23$88f$1@fred.mathworks.com>...
>
> > if I have large arrays of the program becomes very slow.
> >
> > How can I do?
> >
>
> If you have large arrays, it's a bad idea to begin with to load them into finely partitioned cell arrays. It's going to introduce a lot of unnecessary overhead when you manipulate the data as a cell instead of in the original matrix form of a and b.
>
> Still, this might be better:
>
> c= reshape( num2cell( [a(:),b(:)],2) , size(a))

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
cssm us 19 Mar, 2010 13:49:07
reference us 19 Mar, 2010 13:49:07
vectors ventus85 19 Mar, 2010 13:29:08
matrix ventus85 19 Mar, 2010 13:29:08
arrays ventus85 19 Mar, 2010 13:29:08
element ventus85 19 Mar, 2010 13:29:08
concatenation ventus85 19 Mar, 2010 13:29:08
rssFeed for this Thread

Contact us at files@mathworks.com