Matlab - 如何创建相同大小的未知矩阵数表?

时间:2017-09-24 13:11:57

标签: matlab

我想创建具有相同大小的未知数量的矩阵表,所以我不能这样做:

table1 = table(zeros([5,5]),zeros([5,5]),zeros([5,5]), 'VariableNames', {'matrix1','matrix2','matrix3'});

但是在这里我被困了,因为我无法找到如何在没有列出零([5,5])n次的情况下制作这个,我不知道会是什么,所以我不得不编码不知。

顺便说一句,我需要像前面的例子那样设置变量名,但是为它做字符串数组不是问题:)

谢谢:)

1 个答案:

答案 0 :(得分:0)

给定T1第一个表(在您的示例中对应于matrix1),T2为第二个表(matrix1),很快,您可以通过这种方式简单地连接表的组件:

final_table=[T1 T2 ...]

...表示其他组件

给定一组n组件,您可以编写一个连接它们的循环。

可能的实施方式可能是:

% Define the names of the components
t_names{1}='matrix1'
t_names{2}='matrix2'
t_names{3}='matrix3'
t_names{4}='matrix4'
% Get the number of the components
n=length(t_names)
% Initialize the final table
the_table=table
% Loop over the components to add them to the final table
for i=1:n
   the_table=[the_table table(zeros([5,5]),'VariableNames', t_names(i))]
end

希望这有帮助,

Qapla'

相关问题