Storing Multiple Matrices in a Cell array
Afficher commentaires plus anciens
Hello, I am currently attempting to generate 30 different matrices and store them in a cell array, but when I run the program I just have a cell array with 30 copies of the same matrix. What am I doing wrong?
m_A = 20;
ID = 3754;
m_B = .002*ID + 3.1;
J_A = 0.0013*ID + 0.188;
g = -9.81;
i = 1;
n = 30/i;
%stores matrices in a cell array
matrixresults = cell(1, n);
for k = 1:n
%generates A matrices
for M = 0:i:30
%m_C = M; m_D = M;
J_C = .5*M*((.1)^2);
%J_D = J_C;
%tau_A = 10 - M;
matrixresults{k} = [(m_A), 0, -1, 1, 0, 0, 0;
(5*J_A), 0, -0.2, 0, 0, 0, 0;
(10*J_C), 0, 0, -0.1, 0, .1, 0;
0, M, 0, 0, 1, -1, -1;
0, (10*J_C), 0, 0, 0, -0.1, 0.1;
0, m_B, 0, 0, -1, 0, 0;
0.5, -1, 0, 0, 0, 0, 0];
end
end
Thank you!!
Réponses (1)
Andrei Bobrov
le 12 Fév 2018
m_A = 20;
ID = 3754;
m_B = .002*ID + 3.1;
J_A = 0.0013*ID + 0.188;
g = -9.81;
n = 30;
M = 0:n-1;
J_C = .05*M;
mr = repmat([(m_A), 0, -1, 1, 0, 0, 0;
(5*J_A), 0, -0.2, 0, 0, 0, 0;
0, 0, 0, -0.1, 0, .1, 0;
0, 0, 0, 0, 1, -1, -1;
0, 0, 0, 0, 0, -0.1, 0.1;
0, m_B, 0, 0, -1, 0, 0;
0.5, -1, 0, 0, 0, 0, 0],1,1,n);
[m,n,k] = size(mr);
mr([3;11;12] + (0:k-1)*m*n) = [J_C;M;J_C];
matrixresults = squeeze(num2cell(mr,[1,2]));
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!