for loop indexing problem

4 views (last 30 days)
Melissa
Melissa on 26 Jun 2013
Good Afternoon All,
I seem to be having trouble with my indexing for a for loop. I am getting the same values every time the loop is executed. I have a 6x6 matrix as an input and data is extracted from each row of the 6x6 matrix to run through my formula to produce the output which should also be a 6x6 matrix.
Any Suggestions?
Dummy Test Data
Mass=276.7;
I=[11.64 15.8 15.69 -.8 3.2 .9];
ModeShapes=[-0.0215 -0.1682 -0.2146 0.1786 0.1355 -0.0028;
0.4662 -0.2614 -0.0813 -0.0772 0.0042 -0.0261;
-0.1276 -0.8945 0.0951 -0.0358 0.0308 0.0024;
1.0000 -0.1792 1.0000 1.0000 -0.1344 0.5292;
0.1440 1.0000 0.5528 -0.4136 1.0000 0.0781;
0.0508 -0.1289 -0.3124 -0.2263 -0.0161 1.0000];
Code:
function [KE_Distribution_Matrix]= Kinetic_Energy_Distribution(Mass,I,ModeShapes)
% User Input
% Mass: Powertrain Mass (kg)
% I: Moment of Inertia Matrix (1x6 dimension) expressed as
% [Ixx,Iyy,Izz,Ixy,Ixz,Iyz]
% ModeShapes: ModeShapes of the given system (6x6 dimension)
% [X_Mode1, Y_Mode1 Z_Mode1, Theta_Mode1, Rho_Mode1, Phi_Mode1
% X_Mode2, Y_Mode2 Z_Mode2, Theta_Mode2, Rho_Mode2, Phi_Mode2
% X_Mode3, Y_Mode3 Z_Mode3, Theta_Mode3, Rho_Mode3, Phi_Mode3
% X_Mode4, Y_Mode4 Z_Mode4, Theta_Mode4, Rho_Mode4, Phi_Mode4
% X_Mode5, Y_Mode5 Z_Mode5, Theta_Mode5, Rho_Mode1, Phi_Mode5
% X_Mode6, Y_Mode1 Z_Mode6, Theta_Mode6, Rho_Mode6, Phi_Mode6]
%
%Extracting Moment of Inertia Values for KE Distribution Calculation
Ixx=I(1);
Iyy=I(2);
Izz=I(3);
%Indexing value for ModeShapes Matrix (6)
n=length(ModeShapes);
%Calculating KE Distribution for each frequency (row)
for i=1:n
%Extracting values from each row of ModeShapes Matrix
X_Mode(i)=ModeShapes(n,1);
Y_Mode(i)=ModeShapes(n,2);
Z_Mode(i)=ModeShapes(n,3);
Theta_Mode(i)=ModeShapes(n,4);
Rho_Mode(i)=ModeShapes(n,5);
Phi_Mode(i)=ModeShapes(n,6);
%Demoninator of the Distribution Calculation
KE_Dom(i)=(Mass*(X_Mode(i)^2+Y_Mode(i)^2+Z_Mode(i)^2)+Ixx*(Theta_Mode(i)^2)+Iyy*(Rho_Mode(i)^2)+Izz*(Phi_Mode(i)^2));
%KE Distribution for each direction
KE_X(i)=(Mass*(X_Mode(i)^2))/KE_Dom(i);
KE_Y(i)=(Mass*(Y_Mode(i)^2))/KE_Dom(i);
KE_Z(i)=(Mass*(Z_Mode(i)^2))/KE_Dom(i);
KE_Theta(i)=(Ixx*(Theta_Mode(i))^2)/KE_Dom(i);
KE_Rho(i)=(Iyy*(Rho_Mode(i))^2)/KE_Dom(i);
KE_Phi(i)=(Izz*(Phi_Mode(i))^2)/KE_Dom(i);
end
% Distribution as a percetange
KE_XF=KE_X*100;
KE_YF=KE_Y*100;
KE_ZF=KE_Z*100;
KE_ThetaF=KE_Theta*100;
KE_RhoF=KE_Rho*100;
KE_PhiF=KE_Phi*100;
%Kinetic Energy Distribution as a Matrix
KE_Distribution_Matrix=[KE_XF; KE_YF; KE_ZF; KE_ThetaF; KE_RhoF; KE_PhiF];
KE_Distribution_Matrix=KE_Distribution_Matrix';

Accepted Answer

Tom
Tom on 26 Jun 2013
My guess is that these Ns should be Is:
X_Mode(i)=ModeShapes(n,1);
Y_Mode(i)=ModeShapes(n,2);
Z_Mode(i)=ModeShapes(n,3);
Theta_Mode(i)=ModeShapes(n,4);
Rho_Mode(i)=ModeShapes(n,5);
Phi_Mode(i)=ModeShapes(n,6);

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!