Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab-如何创建相同大小的未知数量矩阵表?_Matlab - Fatal编程技术网

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

Matlab-如何创建相同大小的未知数量矩阵表?,matlab,Matlab,我想创建相同大小的未知数量矩阵表,所以我不能这样做: table1 = table(zeros([5,5]),zeros([5,5]),zeros([5,5]), 'VariableNames', {'matrix1','matrix2','matrix3'}); 但在这里我被卡住了,因为我无法找到如何在不列出n次零([5,5])的情况下实现这一点,我不知道n是什么,所以我不得不以某种方式编写代码 顺便说一句,我也需要像上一个例子一样设置变量名,但为其创建字符串数组不是问题:) 谢谢:)给定T

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

table1 = table(zeros([5,5]),zeros([5,5]),zeros([5,5]), 'VariableNames', {'matrix1','matrix2','matrix3'});
但在这里我被卡住了,因为我无法找到如何在不列出n次零([5,5])的情况下实现这一点,我不知道n是什么,所以我不得不以某种方式编写代码

顺便说一句,我也需要像上一个例子一样设置变量名,但为其创建字符串数组不是问题:)


谢谢:)

给定
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

非常感谢,这也是一个很好的解决方案,所以我接受了你的答案。但是在Mathworks上我得到了更简单的解决方案,所以如果有人需要的话,我也想把它贴在这里:
args=cell(1,n);args(:)={zeros([5,5])};table1=table(args{:};