# Thread: Matrix problem in Matlab

1. ## 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.

2. 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.

3. 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?

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?

.

4. 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.

.

5. 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.

6. 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.

7. 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
.

8. Thank you very much to both of you, I will try your suggestion.
I wish you a great 2009!