Need to Produce a different matrix after each loop

Hello Friends,
I need to produce a different set of deli after each loop but it remains the same. Help me out please...see code below.
deli is suppose to be different set of 12 by 1 after each loop
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];
delu=[-107.9277784;-473.7489066;-456.4464814;-298.1506906;-38.38102414;169.6616599;218.8447121;105.0260144;-78.47051372;-205.707;-1.1961463;701.7499816;-2084.55571;-1229.851404;-0.390010302;39.67805573;-68.88297022;2231.216584;-5473.430599;-3189.887351;-0.390010302;41.85037402;-72.64553587];
delr=zeros(49,1);
del=[delu;delr];
deli=zeros(12,1);
delbar=([]);
mbar=repmat({zeros(12,1)},n,1);
for i=1:n
for p=1:12
deli(p,1)=del((L(i,p)),1);
end
mbar{i}=(kg{i}*deli)+fembar{i};
end

3 Commenti

Scott MacKenzie
Scott MacKenzie il 25 Giu 2021
Modificato: Scott MacKenzie il 26 Giu 2021
It would help if you provide code that can be executed. As posted, the code accesses a few uninitialized variables.
It looks to me as if deli is indeed different after each for i loop. You do not ask to record the value for each i value though.
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];
delu=[-107.9277784;-473.7489066;-456.4464814;-298.1506906;-38.38102414;169.6616599;218.8447121;105.0260144;-78.47051372;-205.707;-1.1961463;701.7499816;-2084.55571;-1229.851404;-0.390010302;39.67805573;-68.88297022;2231.216584;-5473.430599;-3189.887351;-0.390010302;41.85037402;-72.64553587];
delr=zeros(49,1);
del=[delu;delr];
deli=zeros(12,1);
delbar=([]);
n = 2; kg = {3;5}; fembar = {2; 103};
mbar=repmat({zeros(12,1)},n,1);
for i=1:n
for p=1:12
deli(p,1)=del((L(i,p)),1);
end
deli
mbar{i}=(kg{i}*deli)+fembar{i};
end
deli = 12×1
-107.9278 0 0 -473.7489 0 0 -456.4465 0 0 -298.1507
deli = 12×1
-456.4465 0 0 -298.1507 0 0 -38.3810 0 0 169.6617
Thank you so much.

Accedi per commentare.

 Risposta accettata

It is my understanding that you want to produce and store the set of deli after each iteration. In your current code the deli produced after each set is correct you just need to store it as well after each iteration. In the code below each column of delstore represents the set of deli after the corresponding iteration.
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];
delu=[-107.9277784;-473.7489066;-456.4464814;-298.1506906;-38.38102414;169.6616599;218.8447121;105.0260144;-78.47051372;-205.707;-1.1961463;701.7499816;-2084.55571;-1229.851404;-0.390010302;39.67805573;-68.88297022;2231.216584;-5473.430599;-3189.887351;-0.390010302;41.85037402;-72.64553587];
delr=zeros(49,1);
del=[delu;delr];
deli=zeros(12,1);
delbar=([]);
delstore=[];
n = 2; kg = {3;5}; fembar = {2; 103};
mbar=repmat({zeros(12,1)},n,1);
for i=1:n
for p=1:12
deli(p,1)=del((L(i,p)),1);
end
delstore=[delstore,deli];
mbar{i}=(kg{i}*deli)+fembar{i};
end

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by