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
3 answers

Deleting empty rows in a 3D cell array in Matlab

I have a large 3D CELL ARRAY (x1) which I have to delete the empty rows. How can I do this? Example of my cell array (some pieces of the variable): val(:,:,1) = [20] [] [] [] [] [] [] [] [ 0] [] [] [] [] [] …
Luiz
  • 85
  • 1
  • 3
  • 12
0
votes
1 answer

Concatenating two column values from a cell array

I have a cell array: cellArray = { '123' 'BC' 'other value'; '124' 'BC' 'other value'; '125' 'BC' 'other value'; '126' 'BC' 'other value'; } I would like to obtain this: cellArray = { '123 BC' 'other value'; '124 BC' 'other…
anon
0
votes
2 answers

Extracting portions of matrix into cell array

I have a pretty large matrix M and I am only interested in a few of the columns. I have a boolean vector V where a value of 1 represents a column that is of interest. Example: -1 -1 -1 7 7 -1 -1 -1 7 7 7 M = -1 -1 7 7 7 -1 -1 7 7 …
Paul Manta
  • 30,618
  • 31
  • 128
  • 208
0
votes
1 answer

Write a nested cell array to an Excel file

I have a variable with nested cells: hello = '8' {1x3 cell} {1x3 cell} '22' {1x3 cell} {1x3 cell} '97' {1x3 cell} {1x3 cell} How do I write this into a single Excel file using MATLAB, e.g. xlswrite('file',hello)?
slowhead
  • 5
  • 5
0
votes
1 answer

How to take the mean of columns from an array within an array?

I am currently working on a project in Matlab where I have a cell array of cell arrays. The first cell array is 464 columns long and 1 row deep. Each of these cells is another cell array that is 96 columns and 365 rows. I need to be able to get the…
0
votes
2 answers

add a constant to a specified column of a matrix for a cell array in matlab

Assume I have a 4x1 cell array,A, inside each cell is a 2x5 matrix, A={[1 1 1 1 1; 2 2 2 2 2]; [3 3 3 3 3; 4 4 4 4 4]; [5 5 5 5 5; 6 6 6 6 6]; [7 7 7 7 7; 8 8 8 8 8]} what I want is to add a constant,let's say 100, to the 4th column of…
tytamu
  • 555
  • 3
  • 11
  • 20
0
votes
2 answers

Evaluate function stored in Matlab cell array

I have a function called objective in Matlab I evaluate by writing [f, df] = objective(x, {@fun1, @fun2, ..., @funN}) in a script. The functions fun1, fun2, ..., funN have the format [f, df] = funN(x). Inside objective I want to, for each input in…
sehlstrom
  • 389
  • 2
  • 7
  • 18
0
votes
1 answer

Why do I get a 0x1 cell? Matlab what function

I'm using the following code to look through all files in a particular directory, and I'm getting some strange results. The point of the program is to do the following: I'm looking through a huge number (~7000+) of .mat files for each day between…
A. Masssey
  • 169
  • 1
  • 3
  • 10
0
votes
1 answer

Cell array manipulation matlab

I need elements from the last cell (say k-th) not occurring in cell before it i.e. (k-1)th cell where k = 1,2,...,p. An example, k=2, r=2^(k+2)+2, n=2^(k)+1; for i=1:k dt = 1:2^i:n; for j=1:2^(k-i)+1 cd(j,:)= dt+ r*(j-1); end …
Kwesi
  • 1
  • 2
0
votes
1 answer

create an new cell array everytime a loop cycles through in matlab

I am new to MatLab but I have some experience with C#. I have a large dataset <169360x97> that I need to break up into 464 cell arrays. I currently have a loop that will cycle through the dataset and make a cell array, but I can not figure out how…
0
votes
2 answers

multiple cell reference

I have a cell array, lets say C. Each cell contains a matrix. For example lets say C is C{1}=[1 2;3 4;5 6] C{2}=[7 8;9 10;11 12] How can I create a new cell array D, whose i-th element is a matrix consisted by the i-th transposed rows of all…
Chris
  • 167
  • 5
0
votes
1 answer

Normalize length of cell array

I have a cell array of length 3 and I want to make a for loop with another cell array with length of 6 , so how can I add extra 3 cells for the first array in order to make the 2 cell arrays equal and to use my for loop in MATLAB? For example, with…
Gloria
  • 329
  • 4
  • 17
0
votes
1 answer

matlab: help in ordering cells contents

This is a part of my code that I need to pick one element from input. The very final result is sorted in a strange way that will create 1X2 cells instead of put them next to each other! struKm(i).seqNam = cellstr(regexp(data(i).Header,…
iAziz
  • 149
  • 1
  • 1
  • 12
0
votes
1 answer

How to conver this text file to proper cell array - Matlab

Alright this is the text…
Furkan Gözükara
  • 22,964
  • 77
  • 205
  • 342
0
votes
1 answer

matlab: merging cell-arrays, converting to time series

i'm fiddling with matlab (no toolboxes added) and am trying to understand how to create x-minute bars from a trade database. accessing the data from SQL server, i get a cell array, Buy_Data: Attributes: [] Data: {619134x2…
E.D.
  • 319
  • 1
  • 5
  • 15