0
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?

1
  • @Jack - That command would get "The right hand side of this assignment has too few values to satisfy the left hand side." There are two solutions depending on if the goal is to remove the cells or to assign empty arrays into them (answered below). Commented Nov 1, 2013 at 2:23

1 Answer 1

1

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}].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.