How to check vector of vectors data structure?
Show older comments
How to check if something is a vector of numbers or vector of vectors?
Answers (1)
You don't tell us any information about what "something" is: is it a cell array or a structure, or a numeric or a custom data class? In lieu of more information about exactly what data you are working with, here is a general answer: MATLAB only lets you nest some data classes: struct and cell in particular, which means if your data is a numeric, logical or character type then it cannot contain any other arrays within itself. So the answer to your question is: check what class data you have, then check its contents IFF it is a cell array or structure.
Follow these steps for some variable X:
- Use isvector(X) to check if X has dimensions 1xN OR Nx1.
- Use class(X) to find what type of data the variable is. Do not rely on what is displayed in the command window.
- IFF you have a struct or a cell, check the data class and shape of its contents using cellfun or structfun, e.g. cellfun(@isvector,X).
Now you know if you have a vector, what class it is, and if it is a cell array, if it also contains vectors. If you are want check that the vectors in a cell array are of a particular class, then you can use this form: cellfun('isclass', X, 'classname'), for any suitable classname.
Categories
Find more on Structures 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!