pick up elements from a cell array and the result must be a cell array

3 ビュー (過去 30 日間)
mohamed Faraj
mohamed Faraj 2019 年 8 月 14 日
編集済み: Guillaume 2019 年 8 月 14 日
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.

採用された回答

Guillaume
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}
retuns a comma separated list of the content of the cells indexed by 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!

その他の回答 (1 件)

madhan ravi
madhan ravi 2019 年 8 月 14 日
cellfun(@(x) reshape(x(1:end-1),[],1), V,'un',0)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by