我正在尝试在表格末尾添加行。例如:
LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];
Tab=table;
s=struct;
for i=1:5
s.name=LastName{i};
s.age=Age(i);
s.heigt=Height(i);
s.weight=Weight(i);
s.BP=BloodPressure(i);
temp=struct2table(s);
Tab(end+1,:)=temp;
end
该表被声明为空,它添加了第一行,但在 for 循环的第二次迭代中给出了以下错误消息:
Subscripted assignment dimension mismatch for table variable 'name'.
我知道发生这种情况是因为变量名称在第二次迭代中有更多字符。有什么方法可以实现吗?
这是我生成的用于解释我的问题的示例代码。在我的实际代码中,问题类似,但结构类型变量是从我无法修改的不同函数返回的。