为具有可变数量条目的结构创建模板 - matlab

时间:2014-09-04 00:29:29

标签: matlab structure

是否有一种简单的方法来创建结构,例如:

>> s
    'nb1': []
    'nb2': []
    'nb3': []
    'nb4': []
    'nb5': []
    'nb6': []
    'nb7': []
    'nb8': []
    'nb9': []
    'nb10': []

理想情况下,我希望能够更改条目数量。所以如果我想要400个条目:

>> s
    'nb1': []
    'nb2': []
       ...
    'nb400': []

1 个答案:

答案 0 :(得分:1)

也许是这样的:

clc
clear

N = 10;
s(N).Value = []; % Set the last value to [], so that all the rest is also initialized to []. Pre-allocation can significantly speed up the code in many cases.

for k = 1:N
s(k).Name = sprintf('nb%i',k)
end

我无法正确测试它,但希望这是你正在寻找的。