# Matrix problem in Matlab

• Dec 28th 2008, 03:21 PM
Tweat
Matrix problem in Matlab
Greetings,

I have a 48x88 matrix and I need to sum the 1st element to the 23rd, the 2nd element to the 24th, etc until the 66th to the 88th (always using a 22 interval).
Then I have to divide 100 by the sum of each column. The result will be multiplied by each element of that same column.

What is the most effective way to do this? Nested for functions?
This is not an undergraduate college question.

Thank you for your replies. I appreciate them.
• Dec 28th 2008, 04:36 PM
Mush
Quote:

Originally Posted by Tweat
Greetings,

I have a 48x88 matrix and I need to sum the 1st element to the 23rd, the 2nd element to the 24th, etc until the 66th to the 88th (always using a 22 interval).
Then I have to divide 100 by the sum of each column. The result will be multiplied by each element of that same column.

What is the most effective way to do this? Nested for functions?
This is not an undergraduate college question.

Thank you for your replies. I appreciate them.

66 loops going from 1 to 23 in steps of 1.

x=0
For i = 1:1:23
x=x+A(i)

x=0
For i = 2:1:24
x=x+A(i)

A bit of copying and pasting and it shouldn't be too bad :P.
• Dec 28th 2008, 07:42 PM
Constatine11
Quote:

Originally Posted by Tweat
Greetings,

I have a 48x88 matrix and I need to sum the 1st element to the 23rd, the 2nd element to the 24th, etc until the 66th to the 88th (always using a 22 interval).

This does not specify what you want done very clearly, is this for each row?

Quote:

Then I have to divide 100 by the sum of each column. The result will be multiplied by each element of that same column.
Is this for the original matrix?

.
• Dec 28th 2008, 07:45 PM
Constatine11
Quote:

Originally Posted by Mush
66 loops going from 1 to 23 in steps of 1.

x=0
For i = 1:1:23
x=x+A(i)

x=0
For i = 2:1:24
x=x+A(i)

A bit of copying and pasting and it shouldn't be too bad :P.

Since dim(A) is [48,88] this is a trifle odd, using a single index accesses the array down the columns one after the other.

.
• Dec 29th 2008, 05:09 AM
Tweat
Hi,

Sorry, I didn't explain myself very well.
I have to normalize the matrix data and my sample is 48 subjects (number of rows).
The result of the division (100/sum of the columns with 22 interval) must be multiplicated by the elements of the original matrix.

Thanks.
• Dec 29th 2008, 05:30 AM
Mush
Quote:

Originally Posted by Constatine11
Since dim(A) is [48,88] this is a trifle odd, using a single index accesses the array down the columns one after the other.

.

Yes indeed, but I'm assuming that the jist of my post was recieved well enough that you could convert my method into one that specifies rows and columns.
• Dec 29th 2008, 07:36 AM
Constatine11
Quote:

Originally Posted by Tweat
Hi,

Sorry, I didn't explain myself very well.
I have to normalize the matrix data and my sample is 48 subjects (number of rows).
The result of the division (100/sum of the columns with 22 interval) must be multiplicated by the elements of the original matrix.

Thanks.

Not the neatest way of doing it but the following script might give you the sums you are looking for (unchecked):

Code:

```a=rand(48,88); ii=1:23; rv=zeros(48,66); for offset=0:65   rv(:,offset+1)=(sum(a(:,ii+offset)')'); end```
.
• Jan 1st 2009, 10:06 AM
Tweat
Thank you very much to both of you, I will try your suggestion.
I wish you a great 2009!