pick up elements from a cell array and the result must be a cell array
3 次查看(过去 30 天)
显示 更早的评论
I want to pick up all elements of a cell array except the last element. When I do V{1:end-1}, the result seems not to be a cell array.
0 个评论
采纳的回答
Guillaume
2019-8-14
编辑:Guillaume
2019-8-14
With a cell array, {} operates on the content of the cells, () operates on the cell array itself.
So, to crop a cell array:
newcellarray = yourcellarray(1:end-1);
Note that
yourcellarray{indices}
edit: so a convoluted way of also cropping the cell array (as long as it is a row cell vector) would be:
newcellarray = {yourcellarray{1:end-1}};
which would unpack all the elements but the last into a comma-separated list and repack it into a new cell array. A bit convoluted!
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!