Re: [讨论] struct a.b([1:5]).c=1; 为什么错?

楼主: celestialgod (天)   2015-06-29 17:47:06
※ 引述《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);
作者: s4300026 (s4300026)   2015-06-29 20:28:00
推荐这篇文章~测试后发现不能用,原因是除了.c外,我还有其他field
楼主: celestialgod (天)   2015-06-29 21:41:00
你只能考虑把其他field一起变成cell再用cell2struct一次转
作者: s4300026 (s4300026)   2015-06-30 08:40:00
囧""

Links booklink

Contact Us: admin [ a t ] ucptt.com