Re: [討論] struct a.b([1:5]).c=1; 為什麼錯?
※ 引述《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://www.ptt.cc/bbs/MATLAB/M.1435571229.A.1D9.html
推
06/29 20:28, , 1F
06/29 20:28, 1F
推
06/29 21:18, , 2F
06/29 21:18, 2F
→
06/29 21:41, , 3F
06/29 21:41, 3F
→
06/29 21:41, , 4F
06/29 21:41, 4F
推
06/30 08:40, , 5F
06/30 08:40, 5F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
MATLAB 近期熱門文章
PTT數位生活區 即時熱門文章