What changes do i need to make so my matrix is not overwritten?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
A K
am 18 Okt. 2016
Bearbeitet: Walter Roberson
am 18 Okt. 2016
I have the following code it runs fine, note where i=1; i want to change it to i=1:3, but i want to store the individual 3 matrices separately. What changes should i make?
Z=ones(n,no_of_stages);
for i=1;
for k=1:no_of_stages
M(k,k)=diag(-phi(i,k));
for d=2:no_of_stages
M(d,d-1)=diag(abs_coeff(i,d));
for r=1:no_of_stages-1;
M(r,r+1)=diag(Z(i,r));
end
end
end
end
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 18 Okt. 2016
Use a cell array indexed by i
2 Kommentare
Walter Roberson
am 18 Okt. 2016
Bearbeitet: Walter Roberson
am 18 Okt. 2016
Z=ones(n,no_of_stages);
for i=1;
clear tM
for k=1:no_of_stages
tM(k,k)=diag(-phi(i,k));
for d=2:no_of_stages
tM(d,d-1)=diag(abs_coeff(i,d));
for r=1:no_of_stages-1;
tM(r,r+1)=diag(Z(i,r));
end
end
end
M{i} = tM;
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!