How to Check if a Variable Holds a Cell Array in MATLAB

The function iscell determines if a variable holds a cell array.


Create a cell array using the following code:

A = {'Peter Pan', 'M', 11; 'Wendy Darling', 'F', 12};


tf = iscell(A) determines if the variable A holds a cell array, and stores the result in the logical variable tf. An equivalent statement is tf = isa(A,'cell').

% Check if A holds a cell array
resultExample1 = iscell(A);
% Check if A holds a cell array (isa)
resultExample2 = isa(A,'cell');
% Check if B holds a cell array
B = 'Hello World!';
resultExample3 = iscell(B);

Further reading

I recommend the following books to learn more on cell arrays in MATLAB.

  1. MATLAB: A Practical Introduction to Programming and Problem Solving (4th Edition)

    This book was the winner of a Textbook Excellence Award. Cell arrays, and other data types, are explained clearly in the eighth chapter.

  2. MATLAB for Engineers (5th Edition)

    This excellent book is especially oriented to engineers and scientists who want to learn MATLAB programming. Chapter 11 explains excellently cell arrays, structure arrays, and character arrays, among other data types.

I also recommend the following pages in the MATLAB help documentation, and the other tutorials in this series.

doc iscell;
doc isa;

Source code

I hope you have learned how to check if a variable holds a cell array in MATLAB. The source code developed in this tutorial is available at this page.


Your friends may need this knowledge to complete a task. Share this tutorial.