Questions tagged [cell-array]

In MATLAB cell arrays are a built-in container class allowing for the storage of different types of data in each "cell" of the array.

A cell array is a data type with indexed data containers called cells, where each cell can contain any type of data. Cell arrays commonly contain either lists of text strings, combinations of text and numbers, or numeric arrays of different sizes.

You can refer to subsets of cells by enclosing indices in smooth parentheses, (). The cell contents can be accessed by indexing with curly braces, {}.

Examples:

>> ca = cell(2, 3);        % create 2-by-3 cell array with empty cells
>> ca{1, 1} = 3;           % store a double scalar in one cell
>> ca{1, 2} = rand(3, 4);  % store an entire matrix into a cell
>> ca{1, 3} = 'will you look at that, a string in a cell!';
>> ca{2, 1} = @mean;       % a function handle can also be stored in a cell
>> ca{2, 3} = uint32(45);  % store a uint32 scalar
>> ca(1, 1:3)   % Get a subset of cells (first row)

ans =

  1×3 cell array

    [3]    [3×4 double]    'will you look at that, a string in a cell!'

>> ca{1, 2}     % Get the contents of a cell

ans =

    0.8147    0.9134    0.2785    0.9649
    0.9058    0.6324    0.5469    0.1576
    0.1270    0.0975    0.9575    0.9706
1035 questions
0
votes
2 answers

MPEG-1 compression - producing macroblocks

I'm stuck with a basic problem in my MPEG-1 compression. I have to produce macroblocks within a image. A macroblock consists of 16 x 16 pixels - where 4 x 8x8 is luminance, 1 x 8x8 is Cb and 1 x 8x8 Cr. In MATLAB I want to produce a cell matrix…
Soren M
  • 129
  • 2
  • 2
  • 6
0
votes
2 answers

How to update multiple graphs from one plot in one statement in Matlab?

I have something like this: p = plot([0 1], [0 1], [1 2], [1 2]); I want to take each pair and append another number. x = get(p, 'XData'); y = get(p, 'YData'); x1 = mat2cell([x{1} double(2)]); y1 = mat2cell([y{1} double(2)]); x2 = mat2cell([x{2}…
Dan
  • 1,555
  • 2
  • 14
  • 30
0
votes
2 answers

Create variables from an array of cells in Matlab

I have an array of cells, for example, cells = {'a', 'b', 'c', d', 'e'}; which is inside a for loop of 1 to 5. I want to create a variable from a to e depending on the loop index, as 1 to a, 2 to b... When I try (i is the for index), eval(cells{i})…
SamuelNLP
  • 4,038
  • 9
  • 59
  • 102
0
votes
3 answers

More verbose error messages with recursive algorithms in Matlab?

BUG: I used cell-arrays in the underlying functions, bad! I cannot understand why restarting Matlab result sometimes into more verbose error messages that help me to actually solve problems. Now I am trying to find a command that makes Matlab…
hhh
  • 50,788
  • 62
  • 179
  • 282
0
votes
1 answer

Issue updating 'cell' values in recursive function (MATLAB)

I have a binary tree that is accessed as a cell array in MATLAB (e.g. a{1}{2}). I was able to write a recursive function (below) that is able to access all the fringe nodes of the tree. My next task is to replace the values at the fringe nodes with…
0
votes
1 answer

Delete cells from cell array without replacing that by NULL

I have a cell which contains cells, I want to delete specific cell from the cell array but with 'delete' function I am getting error as "Argument must contain a string". For example I have a cell A= { ['a'] ['b'] ['c'] [1 2 3]} now i want to delete…
Nitendra
  • 13
  • 3
0
votes
2 answers

Matlab: finding change points in cell array

If I have a cell array CELLS = {'AB','AB','AB','BC','BC','CD','CD','CD','DF','FG'} How do I find the indices of the locations at which the elements change? in this example I'm looking for an output like: CHANGES = 4 6 9 …
siegel
  • 819
  • 2
  • 12
  • 24
0
votes
1 answer

How to make database-like grouping on cell array or struct in Matlab?

I have tabular data in Matlab. It can be stored either in struct or in cell array. How to perform grouping like done with unique(A,'rows')? It is not working for cell arrays for some reason. Are there some approaches? UPDATE >> A={'Morgan', 'male',…
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
0
votes
2 answers

calculating the number of columns in a row of a cell array in matlab

i've got a cell array full of numbers, with 44 rows and different column length in each row how could i calculate the number of columns in each row?(the columns which their contents are not empty) i've used 2 different ways which both of them where…
samdean
  • 113
  • 2
  • 9
0
votes
1 answer

Printing cell array in gui label matlab

I'm really new to matlab programming and I can't figure something out. I spent hours googling and no luck. I'm trying to make an app that will take a text file convert it to binary and then convert the binaries to hamming code. That's the first part…
Filkatron
  • 37
  • 1
  • 7
0
votes
1 answer

Matlab error with vertcat and cell arrays

I'm trying to concatenate two arrays as follows: z={ '35' {'test'} ; '45' {'test'}} z={z{:} ;{'55' {'test'}}} I would expect the result to be {35 {'test'} 45 {'test'} 55 {'test'}} but instead I get: Error using vertcat Dimensions of matrices…
Carbon
  • 3,828
  • 3
  • 24
  • 51
0
votes
1 answer

MATLAB Match a row in a cell array, provided a sample cell array

I need to return matches from a large cell array given one row to match. I wrote this code, but it seems like it shouldn't be this challenging - the code feels overwrought. What's the right way to do this? function locations=…
Carbon
  • 3,828
  • 3
  • 24
  • 51
0
votes
1 answer

How to create matrix from struct

I have a structure PI{1x50cell} with fields x, y, z, xy, t, des. x, y, z, xy, t are doubles. However, des is a 1x640 vector. I would like to have this mapped on a two matrix, the first one will be 50x5 and the second one will be 50x640. How to do…
Ren
  • 1
  • 2
0
votes
2 answers

Copy data from Cell Array into an array of Structures

I'm trying to read a line from a text file. This line would be broken down into words by using textscan. The output from textscan would be stored inside an array of structures. Where each structure stores one word and the location it was at in the…
0
votes
3 answers

Matlab: Save matrix of function handles to a text file

For example my data is: data = [1000] @(x)x.^2 @sin [0.5] [2000] @(x)1./x @cos [0.6] I want to save data to a text file or another. (data is a cell matrix). How can I achieve this?
newzad
  • 706
  • 1
  • 14
  • 29