Check for the existence of a variable inside a structure array

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

Your data is a cell array containing a structure array, not a pure structure array.

댓글을 달려면 로그인하십시오.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 11월 25일
any(ismember(fields(data{1}),'oxy'))

댓글 수: 3

Thank you so much for answering my question. It works great!
and how to chek the existance of data{i}.oxy or data.oxy or data(i).oxy?
Do you have a nonscalar cell array each containing a scalar structure, or a non-scalar struct array?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

태그

질문:

2013년 11월 25일

댓글:

2018년 10월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by