Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: How to apply a function to the columns of a matrix
Replies: 9   Last Post: Dec 25, 2011 2:10 PM

 Messages: [ Previous | Next ]
 andalibar@gmail.com Posts: 17 Registered: 2/28/07
Re: How to apply a function to the columns of a matrix
Posted: Dec 24, 2011 6:58 AM

On Dec 24, 1:24 am, "Matt J " <mattjacREM...@THISieee.spam> wrote:
> Aseman <andali...@gmail.com> wrote in message <71c2925e-ad3a-430f-b9b3-18453386c...@t8g2000yqg.googlegroups.com>...
> > hi
>
> > I should apply my own function fun to the columns of a matrix
> > A(200,000 by 1000). How to do this without cellfun or for loops?
> > any help will be greatly appreciated.

>
> ===============
>
> What's the function?

Dear Matt
This is actually the problem my colleague, Rahill, seek advice about
it. You kindly answered to his question in her past post. Your code
works more faster on each column of the matrix consisting of 180,000
elements, but how we could run it over all 744 columns without any for
loop?

Here is the original problem and your answer.

___________________________________________________________
hello everybody
I am working with a 180,000 by 744 data matrix. At this time, I should
work with each column of this matrix. I should divide each column to
16 segments overlapping by 75%. To reduce the complexity, I have tried
to avoid any loop in my code, as the following

A=reshape(eachColumn,11250,16);
A1=circshift(A,[0,-1]);
A2=circshift(A,[0,-2]);
A3=circshift(A,[0,-3]);
A=[A;A1;A2;A3];

example

A=[1 2 3;4 5 6; 7 8 9;10 11 12;13 14 15]'

A =

1 4 7 10 13
2 5 8 11 14
3 6 9 12 15

ans

A_segmented=

1 4 7 10 13
2 5 8 11 14
3 6 9 12 15
4 7 10 13 1
5 8 11 14 2
6 9 12 15 3
7 10 13 1 4
8 11 14 2 5
9 12 15 3 6
10 13 1 4 7
11 14 2 5 8
12 15 3 6 9

however, I do not know how to apply the above code to all of the 744
columns without using any loop. I tried to do so, by concatenating the
columns, but in this way, MATLAB crashes by 'out of memory' prompt.

any help will be appreciated
Rahill

Matt
One possibility:
A= mod( bsxfun(@plus,(1:12).',3*(0:4))-1,15)+1
__________________________________________________________

Date Subject Author
12/24/11 andalibar@gmail.com
12/24/11 Matt J
12/24/11 andalibar@gmail.com
12/24/11 Matt J
12/24/11 andalibar@gmail.com
12/25/11 Matt J
12/25/11 Matt J
12/25/11 andalibar@gmail.com
12/24/11 Matt J
12/24/11 Nasser Abbasi