How to properly delete cell element ?
629 ビュー (過去 30 日間)
古いコメントを表示
I have a 1x12 cell. How do i remove the last element in the cell ? I tried cell{end} = [] but it did not work. It only emptied the last cell. I would like the result to be a 1x11 cell
0 件のコメント
採用された回答
goerk
2016 年 6 月 27 日
use normal brackets
cell(end) = [];
1 件のコメント
Guillaume
2016 年 6 月 27 日
The reason being:
- curly brackets act on the content of a cell(s). It does not affect the container (the cell array) itself, so c{end} refers to what's in the last cell, and therefore c{end} = [] puts an empty matrix in that last cell.
- round brackets act on the cell array itself. So c(end) refers to the last cell, and c(end) = [] deletes it.
その他の回答 (3 件)
Ceethal Kottakali Piyus
2022 年 1 月 20 日
You have to use round parentheses instead of curly braces (which act on the inner cell values and not on the cells themselves):
cell(end) = [];
Amir Hosein Asaadi
2021 年 9 月 27 日
I sove it by creating variable again like this:
cell_var = {'var1','var2'};
cell_var = {'var1'};
I hope this work for you.
0 件のコメント
Josep Llobet
2022 年 8 月 2 日
% Cell you want to copy
branques_pixels_new = {[55178] [55593] [62271] [62686] [66858] [67273 123123 12123]}
% element you want to eliminate
n_elm_borrar = 3;
% New cell with the non- element
branques_pixels_new_2 = {};
% Operation
for n_elm = 1:length(branques_pixels_new)
if n_elm ~= n_elm_borrar
branques_pixels_new_2{end+1} = branques_pixels_new{n_elm};
end
end
% New cell
branques_pixels_new_2
2 件のコメント
Stephen23
2022 年 8 月 2 日
The simple and efficient MATLAB approach:
branques_pixels_new_2 = branques_pixels_new;
branques_pixels_new_2(n_elm_borrar) = [];
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!