Check for the existence of a variable inside a structure array

1 次查看(过去 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!

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-11-25
any(ismember(fields(data{1}),'oxy'))
  3 个评论
Mr M.
Mr M. 2018-10-16
and how to chek the existance of data{i}.oxy or data.oxy or data(i).oxy?
Walter Roberson
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 CenterFile Exchange 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by