Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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
__________________________________________________________




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.