Reputation: 57
I have a 23x5 cell array, and I'm trying to replace all cells but the first with an empty cell in one column.
When I try array{2:end,4}=[]
I get "The right hand side of this assignment has too few values to satisfy the left hand side."
Still being confused with how Matlab handles different classes, I also tried
array(2:end,4)=[]
and get "A null assignment can have only one non-colon index."
I know a for loop could easily empty the contents of each cell, but I feel like there must be an easier solution to fix this.
Thanks for the help.
Upvotes: 3
Views: 1260
Reputation: 4660
Try using:
array(2:end,4) = {[]}
For example:
>> array = cell(23,5);
>> array(:) = {1};
>> array(2:end,4) = {[]}
array =
[1] [1] [1] [1] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
[1] [1] [1] [] [1]
Upvotes: 6