How to remove the last element from an array of cells in Matlab?

How to remove the last element from an array of cells in Matlab?

The documented method does not work:

>> A = {'a', 'b', 'c'}
A =
  1×3 cell array
    'a'    'b'    'c'
>> A{end}=[]
A =
  1×3 cell array
    'a'    'b'    []

I need an array to become 1x2.

+4
source share
1 answer

You should use parentheses instead of curly braces (which act on the internal values ​​of the cell, not on the cells themselves):

A(end) = [];

For details, see the last section of the official documentation that you indicated:

https://mathworks.com/help/matlab/matlab_prog/delete-data-from-a-cell-array.html

+6
source

Source: https://habr.com/ru/post/1692688/


All Articles