Matlab: Using the exist function within a structure

Click For Summary
SUMMARY

The discussion centers on using the 'exist' function in MATLAB to determine if a specific field within a structure contains data. A user seeks to check if the 'city' field of a structure named 'team' has been populated based on a user-input variable 'identification'. A suggested solution is to utilize the 'isfield' function, which directly checks for the existence of the 'city' field within the 'team' structure, providing a more straightforward approach than 'exist'.

PREREQUISITES
  • Familiarity with MATLAB programming language
  • Understanding of MATLAB structures and fields
  • Knowledge of user input handling in MATLAB
  • Basic understanding of conditional statements in programming
NEXT STEPS
  • Explore the use of 'isfield' function in MATLAB for structure field validation
  • Learn about error handling in MATLAB to manage user input effectively
  • Investigate advanced structure manipulation techniques in MATLAB
  • Study MATLAB's documentation on the 'exist' function for broader applications
USEFUL FOR

MATLAB programmers, data analysts, and anyone working with structures in MATLAB who needs to validate field existence and manage data input 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
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 6 ·
Replies
6
Views
6K