Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matrix question 1

Status
Not open for further replies.

Tweat

Computer
Dec 28, 2008
3
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.
 
Replies continue below

Recommended for you

Yes, nested for loops will do the trick. Very simple to program in Matlab.

cheers,
 
Tweat/Cappola,

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.
 
Given the small size of your matrix, a vectorized approach would be most elegant and quickest. Why not give the CSSMers a holiday golfing problem?

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

Thank you very much to all of you, your help is highly appreciated.
I wish you a great 2009!
 
OK, This is what I *think* you are asking...

% 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
 
Thank you for all the help! I really wish you all have a great year!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor