作者celestialgod (攸蓝)
看板MATLAB
标题Re: [讨论] struct a.b([1:5]).c=1; 为什麽错?
时间Mon Jun 29 17:47:06 2015
※ 引述《s4300026 (s4300026)》之铭言:
: 如题
: 我想要做到
: a.b(1).c = 1
: a.b(2).c = 1
: a.b(3).c = 1
: a.b(4).c = 1
: a.b(5).c = 1
: 就很顺手的打
: a.b([1:5]).c=1;
: 然後就得到
: Insufficient outputs from right hand side to
: satisfy comma separated list expansion on left hand
: side. Missing [] are the most likely cause.
: 该怎麽改成正确呢?
我不知道有没有更好的方法,我找到的方式是这样
a = struct('b', []);
a.b = cell2struct(cellfun(@(x) 1, cell(5,1), ...
'uniformoutput', false), {'c'}, 2);
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 111.248.7.74
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/MATLAB/M.1435571229.A.1D9.html
1F:推 s4300026: 推荐这篇文章~ 06/29 20:28
2F:推 s4300026: 测试後发现不能用,原因是除了.c外,我还有其他field 06/29 21:18
3F:→ celestialgod: 你只能考虑把其他field一起变成cell再用cell2struct 06/29 21:41
4F:→ celestialgod: 一次转 06/29 21:41
5F:推 s4300026: 囧"" 06/30 08:40