MATLAB Matlab: Using the exist function within a structure

Click For Summary
The discussion revolves around using the 'exist' function in MATLAB to check if data has been entered into a specific field of a structure. The user seeks a method to verify the presence of data in the 'city' field of a structure named 'team', indexed by a user-input variable 'identification'. A suggested solution is to use the 'isfield' function instead of 'exist', which checks if the 'city' field exists within the 'team' structure. This approach is recommended for controlling data input into the structure effectively.
craigpmorgan
Messages
8
Reaction score
0
Hi All,

Does anyone if it's possibe to use the 'exist' function in Matlab to check whether any data has been entered into a particular field of a structure. I'd like something like the following, where 'identification' is a user-input variable, 'team' is the structure and 'city' is the field.

identifiaction = input('Enter I.D: ');
X = exist(team(identification).city);

if X == 1;
action

else
action

end

I need this to control where new data is input into the structure. Thanks for your time.

Craig
 
Physics news on Phys.org
try this:

X = isfield(team,'city')
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 14 ·
Replies
14
Views
3K