Loop to populate a 12 by 12 matrix
Show older comments
Hello Guys,
I am tryling to form a 12 by 12 matrix for 11 elements. I am getting some errors. Take a look at my code below: it looks perfect to me but it is not working
SC1=rand(11,1);% Test Data
SC2=rand(11,1);
SC3=rand(11,1);
SC4=rand(11,1);
SC5=rand(11,1);
SC6=rand(11,1);
SC7=rand(11,1);
SC8=rand(11,1);
n=size(SC8,1);
K1=zeros(12,1);
K2=zeros(12,1);
K3=zeros(12,1);
K4=zeros(12,1);
K5=zeros(12,1);
K6=zeros(12,1);
K7=zeros(12,1);
K8=zeros(12,1);
K9=zeros(12,1);
K10=zeros(12,1);
K11=zeros(12,1);
K12=zeros(12,1);
K=zeros(12,12);
for i=1:n
K1(i)=[SC1(i);0;0;0;0;0;-SC1(i);0;0;0;0;0];
K2(i)=[0;SC6(i);0;0;0;SC2(i);0;-SC6(i);0;0;0;SC2(i)];
K3(i)=[0;0;SC7(i);0;-SC3(i);0;0;0;-SC7(i);0;-SC3(i);0];
K4(i)=[0;0;0;SC4(i);0;0;0;0;0;-SC4(i);0;0];
K5(i)=[0;0;-SC3(i);0;(2*SC5(i));0;0;0;SC3(i);0;SC5(i);0];
K6(i)=[0;SC2(i);0;0;0;(2*SC8(i));0;-SC2(i);0;0;0;SC8(i)];
K7(i)=-K1;
K8(i)=-K2;
K9(i)=-K3;
K10(i)=-K4;
K11(i)=[0;0;-SC3(i);0;SC5(i);0;0;0;SC3(i);0;(2*SC5(i));0];
K12(i)=[0;SC2(i);0;0;0;SC8(i);0;SC2(i);0;0;0;(2*SC8(i))];
K(i)=[K1(i) K2(i) K3(i) K4(i) K5(i) K6(i) K7(i) K8(i) K9(i) K10(i) K11(i) K12(i)];
end
1 Comment
DARLINGTON ETAJE
on 24 Jun 2021
Accepted Answer
More Answers (0)
Categories
Find more on Statistics and Machine Learning Toolbox 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!