フィルターのクリア

How to relabel the structures fields in a sequence?

1 回表示 (過去 30 日間)
Sonali
Sonali 2023 年 10 月 26 日
コメント済み: Sonali 2023 年 10 月 26 日
I have a structure A which has 20 fields(bin_1 to bin_20), but i removed some field with null values. Now I am left with the following.
A = struct with fields:
bin_1: [14115×19 table]
bin_17: [9829×19 table]
bin_18: [11772×19 table]
bin_19: [14115×19 table]
Now I need program that converts the bin_ indices automatically to a sequence:
A = struct with fields:
bin_1: [14115×19 table]
bin_2: [9829×19 table]
bin_3: [11772×19 table]
bin_4: [14115×19 table]
Will really appreciate some help here. Thanks
  1 件のコメント
Stephen23
Stephen23 2023 年 10 月 26 日
You would not need to do this if you used a non-scalar structure. Better data design makes this problem disappear.

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

採用された回答

Walter Roberson
Walter Roberson 2023 年 10 月 26 日
newfields = "bin_" + (1:length(fieldnames(A)));
A = cell2struct(struct2cell(A), newfields);
  1 件のコメント
Sonali
Sonali 2023 年 10 月 26 日
Thanks. This worked well for me.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by