Check for the existence of a variable inside a structure array

1 Ansicht (letzte 30 Tage)
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 Kommentar
Walter Roberson
Walter Roberson am 16 Okt. 2018
Your data is a cell array containing a structure array, not a pure structure array.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 25 Nov. 2013
any(ismember(fields(data{1}),'oxy'))
  3 Kommentare
Mr M.
Mr M. am 16 Okt. 2018
and how to chek the existance of data{i}.oxy or data.oxy or data(i).oxy?
Walter Roberson
Walter Roberson am 16 Okt. 2018
Do you have a nonscalar cell array each containing a scalar structure, or a non-scalar struct array?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by