본문으로 건너뛰기
Hub Nexus
업데이트됨

작성자아직 작성자가 없습니다맡기

개선할 점이 보이나요? 변경을 제안하세요.

후원

이 페이지는 공개 상태입니다.

Cell Arrays can contain differing information in every element. These types of arrays are useful when interacting with spreadsheet software.

Creating Cell Arrays

Cell arrays follow the same conventions as regular arrays except instead of square brackets use curly brackets.

array = [1, 2, 3; 4, 5, 6];
cell_array = {1, 2, 3; 4, 5, 6};

Cell arrays have fewer limitations than regular arrays. The regular array can hold strings; however, the string in each element must be the same length. If one element in a regular array is a string then all elements must be a string. Cell arrays have neither of these limitations.

cell_array = {1, 2, 'a', 'abc'; rand(3, 2), magic(3), eye(3), 'junk'}
cell_array =
[ 1] [ 2] 'a' 'abc'
[3x2 double] [3x3 double] [3x3 double] 'junk'

With fewer limitations for the content of a cell array comes complications. While cell arrays are a powerful tool, these arrays work differently because each element can be almost anything.

Dynamic Resizing

Cell arrays can be dynamically resized, which is a key feature in more advanced data structures. For example, a queue data structure using the commands:

cell_array{end+1}='a';
cell_array{end+1}='b';

An element can be popped from the front of the queue using the commands:

cell_array(1)=[]; % remove first element - resize
cell_array(1)=[]; % remove first element - resize

Uses

GUI Tables

Cell arrays are used when displaying a table to a figure.

uitable('Data',{'hello',1;2,'there'})

Converting to and from cell arrays

Converting From a Numeric Array into a Cell Array

Use num2cell to convert from a numeric into a cell array.

>> cell_array = num2cell(numeric_array);

Converting From a Cell Array into a Numeric Array

Use cell2mat to convert from a cell into a numeric array.

>> numeric_array = cell2mat(numeric_cell_array);

ControlTheoryPro.com

Where this page came from

This page was imported from Wikibooks. From “MATLAB Programming” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

이 페이지가 속한 매거진MATLAB Programming

언어English

이용 허락: CC BY-SA 4.0 · 출처 en.wikibooks.org

견해

코멘트

Spinner Logo
버전: 2CC0 1.0 (퍼블릭 도메인)
The runaway star that left the Tarantula Nebula
버전: 2CC0 1.0 (퍼블릭 도메인)
The Eagle Nebula, seen in the infrared
버전: 2CC0 1.0 (퍼블릭 도메인)
The Cosmic Cliffs are not cliffs
버전: 2CC0 1.0 (퍼블릭 도메인)
The recommended targets are real, but the largest health gain is between doing nothing and doing a little. That is the part worth knowing if you are starting from nothing.
버전: 2CC0 1.0 (퍼블릭 도메인)
Sleep is not one state but a cycle through several, each doing different work. Most sleep disorders are a failure to complete that cycle rather than a shortage of hours.
버전: 2CC0 1.0 (퍼블릭 도메인)
Four nebulae that revealed the shape of our galaxy