Discard elements from structure array
1 回表示 (過去 30 日間)
古いコメントを表示
I have a structure with one field. I try to remove specific elements using i.e.:
trial(5).Hs_m = []
but the element remains in the structure, just having a value of "[]". Is there a way to remove it?
0 件のコメント
回答 (1 件)
Massimo Zanetti
2017 年 2 月 25 日
編集済み: Massimo Zanetti
2017 年 2 月 25 日
Here is an example:
S.field1 = 'hello';
S.field2 = 456;
S
S =
struct with fields:
field1: 'hello'
field2: 456
Now remove one field:
S = rmfield(S,'field1')
S =
struct with fields:
field2: 456
2 件のコメント
Massimo Zanetti
2017 年 2 月 25 日
編集済み: Massimo Zanetti
2017 年 2 月 25 日
So, why mentioning the field? In this case just remove the structure entry. Following your example, you can remove the 5-th entry with
trial(5) = []
regardless of the field(s).
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!