这是我正在寻找的一个例子:
>> foo = [88, 12];
>> [x, y] = foo;
Run Code Online (Sandbox Code Playgroud)
之后我会期待这样的事情:
>> x
x =
88
>> y
y =
12
Run Code Online (Sandbox Code Playgroud)
但相反,我得到的错误如下:
??? Too many output arguments.
Run Code Online (Sandbox Code Playgroud)
我想deal()可能会这样做,但它似乎只适用于细胞.
>> [x, y] = deal(foo{:});
??? Cell contents reference from a non-cell array object.
Run Code Online (Sandbox Code Playgroud)
我该如何解决我的问题?如果我想单独处理它们,我必须经常索引1和2吗?
在逗号sep上结合使用此问题和Mathworks帮助.列表我提出了这种丑陋的方式使我的格式化参数更漂亮:
formatting{1,1} = 'color'; formatting{2,1} = 'black';
formatting{1,2} = 'fontweight'; formatting{2,2} = 'bold';
formatting{1,3} = 'fontsize'; formatting{2,3} = 24;
xlabel('Distance', formatting{:});
Run Code Online (Sandbox Code Playgroud)
但它仍然有点难看...有没有办法将结构解压缩成一堆Python字典的参数**kwargs?
例如,如果我有(恕我直言)清洁结构:
formatting = struct()
formatting.color = 'black';
formatting.fontweight = 'bold';
formatting.fontsize = 24;
Run Code Online (Sandbox Code Playgroud)
我能以某种方式通过吗?如果我直接尝试(xlabel('blah', formatting)或者formatting{:},它会说"错误的论点数".