How do i delete an exact cell from a cell-matrix?

3 ビュー (過去 30 日間)
Christoph Thale
Christoph Thale 2016 年 9 月 7 日
コメント済み: Mischa Kim 2016 年 9 月 7 日
Hi,
i have a 1x13 cell-txt-matrix which is read out of an excelsheet with
[num, txt, raw] = xlsread(___)
txt looks like that:
[test] [1.1.111] [2.2.2222] [empty cell] [3.3.3333]
the [ ] stands just for the cell. There are no brackets in it.
I am able to identify the coordinates from the cells i want to delete. The problem is, I cant delete these founded cells. I want to have this:
[1.1.111] [2.2.2222] [3.3.3333]
I tried to solve this problem with the approach:
txt{...} = []
The receiving:
[[]] [1.1.111] [2.2.2222] [[]] [3.3.3333]
I hope you understand my problem and have some satisfying advices.
Thanks a lot.

採用された回答

Mischa Kim
Mischa Kim 2016 年 9 月 7 日
Christoph, simply use round brackets instead
a = {1,2,3};
a(2) = []
  3 件のコメント
Noam Weissman
Noam Weissman 2016 年 9 月 7 日
編集済み: Noam Weissman 2016 年 9 月 7 日
a(2) is a cell with size 1x1.
a{2} is the content of the above cell.
You want to delete the cell itself, not only its content.
Mischa Kim
Mischa Kim 2016 年 9 月 7 日
I agree, this is not obvious.
There is a difference between removing a cell element and setting a cell element to "empty". Since the curly brackets are used to assign cell values, this approach is also used to assign an empty cell value. Therefore, there needs to be a different mechanism to remove a cell element. That is where the round brackets come in in.
Also note, that for matrices you use the same approach:
a = [1,2,3];
a(2) = []
a =
1 3

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

その他の回答 (1 件)

Noam Weissman
Noam Weissman 2016 年 9 月 7 日
編集済み: Noam Weissman 2016 年 9 月 7 日
txt = txt([2 3 5]);
% or
txt([1 4 ])=[];
  1 件のコメント
Christoph Thale
Christoph Thale 2016 年 9 月 7 日
編集済み: Christoph Thale 2016 年 9 月 7 日
Haha, of course i can solve it with your first attempt for this example but the cells i wont have in my cell-matrix are variable.
Thank you, the round brackets work fine.

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by