Use a wildcard to look for values in struct

26 ビュー (過去 30 日間)
Dc215905
Dc215905 2020 年 3 月 13 日
コメント済み: Dc215905 2020 年 3 月 13 日
I have a nested struct where I always know the name of the first and last level, but the way the data gets exported into matlab the middle field will always be different.
For example:
data.A005_RC_B.value
I'd like to be able to load data into the GUI and not have to worry about the renaming. Is it possible to call a variable using a wildcard so that if I load a file it I can see what 'value' is by:
data.*.value
If that's not possible, is it possible to remove the middle field or rename the middle field. It's really unecessary but I can't do anything about it because of how the software I'm using exports their data into matlab.
Thanks

採用された回答

Mohammad Sami
Mohammad Sami 2020 年 3 月 13 日
Is there only one middle field ?
If thats the case you can do as follows
% s = your struct
f = filednames(s);
v = getfield(s,f{1},'value');
  1 件のコメント
Dc215905
Dc215905 2020 年 3 月 13 日
Thank you! That works great!

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

その他の回答 (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