在单元阵列中存​​储多个矩阵(Matlab)

时间:2018-02-12 04:29:00

标签: arrays matlab for-loop matrix

我目前正在尝试生成30个不同的矩阵并将它们存储在单元格数组中,但是当我运行程序时,我只有一个包含30个相同矩阵的单元格。我做错了什么?

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
        J_C = .5*M*((.1)^2); 
        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

1 个答案:

答案 0 :(得分:0)

试试这个:

clc; clear;
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
A = cell(1, n);
for k = 1:i:30
        J_C = .5*k*((.1)^2); 
        A{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, k, 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