poster
2019-12-10, 16:49
我想操纵一个单元格数组并使该单元格数组的某些索引包含空矩阵[] 。我似乎无法弄清楚如何做到这一点:
>> yy=num2cell(1:10) yy = [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] >> yy{1:2:end}=[] ??? The right hand side of this assignment has too few values to satisfy the left hand side. >> yy(1:2:end) = [] yy = [2] [4] [6] [8] [10] 呸!似乎无法做到我想要的。我想在单元格数组中保留空元素,例如
[] [2] [] [4] [] [6] [] [8] [] [10] 有什么建议么?我的索引向量可以是任意的,可以是索引形式也可以是布尔形式,不一定是[1 3 5 7 9]。
回答:
您可以做的是使用()索引单元格数组(而不是内容() ,并将每个单元格更改为一个空单元格{[]} :
yy(1:2:end) = {[]}; 一种替代方法是使用DEAL (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/deal.html)函数,但看起来有点难看:
[yy{1:2:end}] = deal([]);
更多&回答... (https://stackoverflow.com/questions/1903191)
>> yy=num2cell(1:10) yy = [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] >> yy{1:2:end}=[] ??? The right hand side of this assignment has too few values to satisfy the left hand side. >> yy(1:2:end) = [] yy = [2] [4] [6] [8] [10] 呸!似乎无法做到我想要的。我想在单元格数组中保留空元素,例如
[] [2] [] [4] [] [6] [] [8] [] [10] 有什么建议么?我的索引向量可以是任意的,可以是索引形式也可以是布尔形式,不一定是[1 3 5 7 9]。
回答:
您可以做的是使用()索引单元格数组(而不是内容() ,并将每个单元格更改为一个空单元格{[]} :
yy(1:2:end) = {[]}; 一种替代方法是使用DEAL (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/deal.html)函数,但看起来有点难看:
[yy{1:2:end}] = deal([]);
更多&回答... (https://stackoverflow.com/questions/1903191)