Navigating Struct and Double issues

2 vues (au cours des 30 derniers jours)
DARLINGTON ETAJE
DARLINGTON ETAJE le 24 Juin 2021
Modifié(e) : Asvin Kumar le 30 Juin 2021
My code is showing me some errors that I cannot explain. Please kindly help me resolve it. Please use input as is. I appreciate you all.
%% Input
L1=[1 33 34 2 35 36 3 37 38 4 39 40];
L2=[3 37 38 4 39 40 5 41 42 6 43 44];
L3=[5 41 42 6 43 44 7 45 46 8 47 48];
L4=[7 45 46 8 47 48 9 49 50 10 51 52];
L5=[9 49 50 10 51 52 11 53 54 12 55 56];
L6=[11 53 54 12 55 56 13 57 58 14 59 60];
L7=[13 57 58 14 59 60 15 61 62 16 63 64];
L8=[15 61 62 16 63 64 17 65 66 18 67 68];
L9=[17 65 66 18 67 68 19 69 70 20 71 72];
L10=[19 69 70 20 71 72 21 22 23 24 25 26];
L11=[21 22 23 24 25 26 27 28 29 30 31 32];
L=[L1;L2;L3;L4;L5;L6;L7;L8;L9;L10;L11];
fem_all=zeros(11,12);% Test data
fem_all(1,1)=-13000;
fem_all(1,7)=-13000;
fem_all(1,4)=2000;
fem_all(1,10)=-2000;
fem_all(end-1,1)=14000;
fem_all(end-1,7)=14000;
fem_all(end-1,4)=450;
fem_all(end-1,10)=450;
fem_all(end,1)=-1234;
fem_all(end,7)=-1234;
uu=32;
ur=40;
Start_r=uu+1;
End_r=uu+ur;
ur1=Start_r:1:End_r;
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);
uru=ur+uu;%these formulas stay same
%
p1=uu-13;
p2=uu-12;
p3=p1+2;
p4=p2+4;
p5=p1+8;
fem_added=zeros(uru,1);
fem_added(1,1)=-13000;
fem_added(2,1)=2000;
fem_added(3,1)=-13000;
fem_added(4,1)=-2000;
fem_added(p1,1)=14000;
fem_added(p2,1)=450;
fem_added(p3,1)=12500;
fem_added(p4,1)=-450;
fem_added(p5,1)=12000;
%
ktotal=zeros(uru);
knew=zeros(uru);
First_row=rand(11,3);
Second_row=rand(11,3);
Third_row=rand(11,3);
CT=([]);
for ict=1:n
CT{ict}=[First_row(ict,:);Second_row(ict,:);Third_row(ict,:)];
end
T=([]);
for ti=1:1:n
T{ti}=blkdiag(CT{ti},CT{ti},CT{ti},CT{ti});
end
kg=([]);
K1 = repmat({zeros(12,1)},n,1);
K2 = repmat({zeros(12,1)},n,1);
K3 = repmat({zeros(12,1)},n,1);
K4 = repmat({zeros(12,1)},n,1);
K5 = repmat({zeros(12,1)},n,1);
K6 = repmat({zeros(12,1)},n,1);
K7 = repmat({zeros(12,1)},n,1);
K8 = repmat({zeros(12,1)},n,1);
K9 = repmat({zeros(12,1)},n,1);
K10 = repmat({zeros(12,1)},n,1);
K11 = repmat({zeros(12,1)},n,1);
K12 = repmat({zeros(12,1)},n,1);
K = repmat({zeros(12,1)},n,1);
fembar=([]);
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{i};
K8{i} = -K2{i};
K9{i} = -K3{i};
K10{i} = -K4{i};
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)];
Ttr=T{i}';
kg(i)=Ttr*K{i}*T{i};
for p=1:12
for q=1:12
knew((L(i,p)),(L(i,q)))=kg(p,q);
end
end
ktotal=ktotal+knew;
fembar(i)=T{i}*fem_all(i);
end
kunr=zeros(uu);
for x=1:uu
for y=1:uu
kunr(x,y)=ktotal(x,y);
end
end
kuuInv=inv(kunr);
j1=(-1).*fem_added;
jlu=j1(1:uu,:); % load vector
% values given in KN or KNm
delu=kuuInv*jlu;
dlr=size(ur1,2);
delr=zeros(dlr,1);
del=[delu;delr];
deli=zeros(12,1);
delbar=([]);
mbar=([]);
for i=1:n
for p=1:12
deli(p,1)=del((L(i,p)),1);
end
delbar(i)=deli(i);
mbar(i)=(kg(i)*delbar(i))+fembar(i);
end

Réponses (1)

Asvin Kumar
Asvin Kumar le 30 Juin 2021
Modifié(e) : Asvin Kumar le 30 Juin 2021
This is a lot of code to debug and not in format that invites help from the community. Please have a look at this post on the best practices while asking questions in this community. In short, provide a Minimum Working Example and give details about the error message that you are seeing. Also a good practice to mention what all you have tried in order to solve that error that you're seeing.
To answer the original question, the issue seems to be in line 102.
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)];
K1(i), K2(i), K3(i), ... are all 1x1 cells which contain a 12x1 array inside it. So, the RHS evaluates to a 12x1 cell array where each cell contains a 12x1 numeric array. Doesn't seem like this is what you want to assign into K{i}. I say this because of the way the variable K is used in the lines following the mentioned statement.
If you want to access any one array from a particular cell in K1, K2, etc. then use curly braces { } instead of parantheses. Curly braces will return the contents of each cell whereas parantheses will return a cell.
Even with that change it looks like you will have a 12x12=144 element array on the RHS while you are expecting a 12 element array for the LHS. I don't have suggestions here since I'm not sure of the algorithm. You can take a call on this.

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by