## Matrix question

## Matrix question

(OP)

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.

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.

## RE: Matrix question

cheers,

## RE: Matrix question

Can you please inform me on what nested for loops refers to and how it can be used.

Tweat,

I do not have access to my computer that has Matlab installed until the new year so I will try and help you however I can.

It seems like you are asking two questions. To answer you first questions regarding summing every 23 rows of each column? If [A] is your 48 x 88 matrix.

for j=1:88

for i=1:26

A1(i,j)=sum(A(i:i+22,j));

end

end

May I ask what you are using Matlab for? I am a structural engineer and I have programmed my own finite element routine and I am in the process of programming steel and concrete design modules. I have access to certified finite element, steel and concrete design programmes, I just feel more assured when I have programmed the logic myself.

## RE: Matrix question

## RE: Matrix question

- Steve

## RE: Matrix question

The result of the division (100/sum of the columns with 22 interval) must be multiplicated by the elements of the original matrix.

Thank you very much to all of you, your help is highly appreciated.

I wish you a great 2009!

## RE: Matrix question

% start with 48 x 88 matrix, A

% add col 1 to col 23, col 2 to col 24 ... col 66 to 88

B = A(:,1:66) + A(:,23:88)

% this gives a 48 x 66 matrix

% sum the columns of B and find 100/sum

C = 100./sum(B);

% this gives a 1 x 66 matrix

Now this is what I don't understand. When you say multiply by the elements of the "original" matrix, do you mean matrix A or matrix B. It won't work for matrix A!

D = B*diag(C);

% D is 48 x 66

Of course you can put all this into 1 line of code, but I have split it up to make it more obvious.

M

--

Dr Michael F Platten

## RE: Matrix question