How do I assign an empty matrix to elements of a cell array in MATLAB?
I want to manipulate a cell array and make certain indices of the cell array contain the empty matrix []. I can't seem to figure out how to do this:
>> 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]
Bah! Can't seem to do what I want. I want to leave empty elements in the cell array, e.g.
  []    [2]    []    [4]    []    [6]    []    [8]    []    [10]
Any suggestions? My index vector could be arbitrary, and either in index form or boolean form, not necessarily [1 3 5 7 9].
What you can do is index the cell array (not the contents) using () and change each cell to an empty cell {[]}:
yy(1:2:end) = {[]};
An alternative is to use the DEAL function, but it looks a bit uglier:
[yy{1:2:end}] = deal([]);
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论