8.5 Other data classes and data structures
We have already seen and used several classes of MATLAB data: double
, representing real numbers; char, representing character data; and logical, representing Boolean data. Arrays can be formed from each of these. One-dimensional arrays of char we call “strings.”
v=-1.234; % double
vec=[1, 2.2, 4]; % vector of double
M=[4, 1; 2, 1.2]; % 2D array of double = matrix
keypressed='k'; % char
myline='now go'; % 1D array of char = string
CM=[ ['a', 'b']; ['c', 'd'] ]; % 2D array of char
isDone=true; % logical
switchIsOn=[true, false, false, true]; % vector of logical
isBig=(M>1); % matrix of logical
There are several other MATLAB data classes that will prove useful. The first two are examples of heterogenous aggregation, that is, gathering information of different types together into one container, i.e., a MATLAB variable. Cell arrays are an extension of the by-now-familiar array idea to include different types of data as elements in the array. Structures, the class struct
, aggregate different types of data that are labeled by names, rather than by indices. These would be more advanced topics we could differ to later but for the fact that a particular structure, called handles
, plays a crucial role in managing GUI ...
Get Learning to Program with MATLAB: Building GUI Tools now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.