Reputation: 441
for i=1:30
a{i}=rand(2,2);
end
a{[6 23]}=[] %get an error here
How do I access element 6 and 23 efficiently?
Upvotes: 0
Views: 724
Reputation: 30579
If you want to assign emptys array to the contents of those two cells, you can use the brackets ([]
) and deal
:
[a{[6 23]}]=deal([])
If instead you want to remove those two cells entirely, use parentheses:
a([6 23])=[]
The reason a{[6 23]}=[]
gives an error is because accessing a cell array that way returns a comma-separated list of the cell contents. In other words, doing [a{[6 23]}]
is like doing [a{6},a{23}]
.
Upvotes: 1