Check for the existence of a variable inside a structure array
3 ビュー (過去 30 日間)
古いコメントを表示
I have a structure array:
data{1} =
date: 19580508
lon: 159.3833
lat: -23.4667
depth: [12x1 single]
temp: [12x1 single]
sal: [12x1 single]
oxy: [12x1 single]
Some of them have the variable 'oxy', others don't. I am trying to figure out how to check for the existence of 'oxy'.
I tried to use A = existence('data{1}.oxy'), but its results are always 0, even when the variable exists.
Should I use some other function to achieve this? Thanks!
1 件のコメント
Walter Roberson
2018 年 10 月 16 日
Your data is a cell array containing a structure array, not a pure structure array.
採用された回答
Azzi Abdelmalek
2013 年 11 月 25 日
any(ismember(fields(data{1}),'oxy'))
3 件のコメント
Walter Roberson
2018 年 10 月 16 日
Do you have a nonscalar cell array each containing a scalar structure, or a non-scalar struct array?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!