Cell Arrays
Cell arrays contain data in cells that you access by numeric indexing. Common applications of cell
arrays include storing separate pieces of text and storing heterogeneous data from spreadsheets.
For example, store temperature data for three cities over time in a cell array.
temperature(1,:) = {'2009-12-31', [45, 49, 0]};
temperature(2,:) = {'2010-04-03', [54, 68, 21]};
temperature(3,:) = {'2010-06-20', [72, 85, 53]};
temperature(4,:) = {'2010-09-15', [63, 81, 56]};
temperature(5,:) = {'2010-12-09', [38, 54, 18]};
temperature
temperature=5×2 cell array
{'2009-12-31'}
{[ 45 49 0]}
{'2010-04-03'}
{[54 68 21]}
{'2010-06-20'}
{[72 85 53]}
{'2010-09-15'}
{[63 81 56]}
{'2010-12-09'}
{[38 54 18]}
Plot the temperatures for each city by date.
allTemps = cell2mat(temperature(:,2));
dates = datetime(temperature(:,1));
12 Cell Arrays
12-18
Précédent

- 554/1450

Suivant