Skip to content
MATLAB

Cell Arrays e Structs

Contêineres de dados heterogêneos no MATLAB.

#cell#struct#data

Code

matlab
% Cell arrays (mixed types)
C = {'hello', 42, [1 2 3], struct('name', 'Bob')};

% Access with {} (content) vs () (cell)
C{1}     % 'hello' (string)
C(1)     % {'hello'} (1x1 cell)

% Cell array of strings
names = {'Alice', 'Bob', 'Carol'};
strcmp(names{1}, 'Alice')  % 1 (true)

% Structs
s.name = 'Alice';
s.age = 30;
s.scores = [90 85 92];

% Array of structs
people(1).name = 'Alice'; people(1).age = 30;
people(2).name = 'Bob';   people(2).age = 25;

% Struct array field access
[people.age]  % [30 25]