Using a for loop to fill up a matrix
Show older comments
Novice here, and I can't figure out how to fill up a matrix using the for loop. The program computes the correct values, but the output is really unprofessional looking. I should be able to get the three output matices: A matrix, CLa and CDia. After each pass in the loop, in the A matrix I should get a column of length four, and the CLa and CDia matrices yield one value each for each pass through the loop.
Here is my program: (I know it's ugly, but I'm new and it works!). The meat of the program is down where the n matrix goes through and uses each successive value of alfa. Right below that is where I want the matrices to start filling up.
for alfa = [-2:2:12],
format long e;
theta=[22.5 45 67.5 90];
k1=sin(theta*pi/180);
k2=sin(3*theta*pi/180);
k3=sin(5*theta*pi/180);
k4=sin(7*theta*pi/180);
k=[k1;k2;k3;k4];
mu=0.24933*(1-0.6*cos(theta*pi/180));
l1=mu+k1;
l2=3*mu+k1;
l3=5*mu+k1;
l4=7*mu+k1;
l=[l1;l2;l3;l4];
m1=k1.*l1;
m2=k2.*l2;
m3=k3.*l3;
m4=k4.*l4;
m=[m1;m2;m3;m4];
n=((alfa+1.2)*pi/180)*(mu.*k1);
A(:,:)=m'\n'
CLa(1,:)=A(1)*pi*9
CDia(1,:)=(CLa^2/(9*pi))*(1 + 3*A(2)^2/A(1)^2 + 5*A(3)^2/A(1)^2 + 7*A(4)^2/A(1)^2)
end;
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!