I'm trying to write a function with a matrix (specifically a matrix) as the output, the rows of which show a double-type variable and a binary 'status'. For no real reason and just out of curiosity, I wonder if there is a way to have the rows to have different types.
Many Thanks
MATLAB offers two viable options for storing mixed data types:
You can look at a cell array as a special matrix where and each element (called cell) can be of a different type (and size). For instance:
C = {2, 'Hello'}
is a cell array that stores both a double and a string.
Structures can also store values of different data types and sizes, each in a different field. For example, the information in the cell array above can be represented as a structure in the following way:
S.count = 2
S.name = 'Hello'
Recommendation:
It seems that a struct looks more elegant for your needs; I suppose you'll have a field called status
storing a boolean value and a field called number
storing a double. For multiple values you can store a vector of booleans in status
and a vector of doubles in number
. Alternatively you can have an array of structs holding one boolean and one double each.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With