Matlab:基于具有指定尺寸的字符串的suplots数量

Matlab: number of suplots based on a string with dimensions specified

我需要决定我需要多少个子图及其大小,所有信息都存储在一个字符串中。

假设有四个子图,它们的大小是:

顶部:1x1 下一张:2x1 下一张:2x1 底部:1x1

基本上中间两个是两个组合对。通常,我会按如下方式指定子图:

subplot(6,1,1)
subplot(6,1,[2:3])
subplot(6,1,[4:5])
subplot(6,1,6)

现在,此信息存储在如下所示的字符串中:

'1;[2:3];[4:5];6'

因此,问题是从此类字符串中获取轴信息的最有效方法是什么。

当然,我可以检查字符串中的每个字符,无论是 ','';''['':' 还是 ']'。这将需要循环到 length(str) 和许多 if 语句,配对 '['':'']'、询问 'is the character numeric?'、'is it colon, then?' 等.这很乏味。

我有几十个这样的子图,我只能认为必须有更好的方法来做到这一点。

假设字符串存储在str

str='1;[2:3];[4:5];6'
splits=strsplit(str,';');
splits=cellfun(@str2num,splits,'uni',0);
for i=1:numel(splits)
    subplot(numel(splits),1,splits{i});
    %plot
end