How to Check if Element of Array Exists?
Show older comments
I have an array of strings which varies in size depending on the number of words in a file name. One file might result in an array of animals[dog, cat, fish], whilst the next might be animals[horse, bird, dog, cat, snake]. If, say, the fifth element of animals is snake, then I will have the program do something. However, this only works if the array is at least 5 elements long. Using my first example would result in an Error, as it only has three elements. Is there a way to check if the array has x elements before I check the xth element?
Accepted Answer
More Answers (0)
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!