Remove element in multidimensional cell array

6 ビュー (過去 30 日間)
dj1du
dj1du 2022 年 6 月 8 日
編集済み: Stephen23 2022 年 6 月 8 日
Good evening,
I have a multi-dimensional cell array c{a}{b} which is indexed by the parameters a=1,...,10 and b=1,...8. Now I'd like to remove e.g. the element a=1, b=3 via c{1}{3}=[], but this only adds zeros. What I am looking for is a Matlab command for the complete removal of c{1}{3}, such that the cell's size is shrinked to b=1,...7. By which command can I achieve this?
  1 件のコメント
Stephen23
Stephen23 2022 年 6 月 8 日
編集済み: Stephen23 2022 年 6 月 8 日
"I have a multi-dimensional cell array c{a}{b}"
I do not see any multidimensional arrays in your examples. You only show nested cell arrays.
MATLAB has actual multi-dimensional arrays (not like many poor low-level langaues that rely on ugly and complicated nested lists that they pretend are multi-dimensional arrays).

サインインしてコメントする。

回答 (1 件)

Stephen23
Stephen23 2022 年 6 月 8 日
編集済み: Stephen23 2022 年 6 月 8 日
You used the wrong type of brackets. You used curly braces to place an empty array inside one cell. The reason why you wrote that "this only adds zeros" is because your description does not match your example.
You need to use parentheses to refer to the cell array itself:
a = 10;
b = 8;
c = arrayfun(@(n)num2cell(n:n+b-1),1:a,'uni',0)
c = 1×10 cell array
{1×8 cell} {1×8 cell} {1×8 cell} {1×8 cell} {1×8 cell} {1×8 cell} {1×8 cell} {1×8 cell} {1×8 cell} {1×8 cell}
c{1}
ans = 1×8 cell array
{[1]} {[2]} {[3]} {[4]} {[5]} {[6]} {[7]} {[8]}
c{1}(3) = [];
c{1}
ans = 1×7 cell array
{[1]} {[2]} {[4]} {[5]} {[6]} {[7]} {[8]}

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by