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
-1
votes
1 answer

setxor single value of cell array with whole cell array values?

My cell array,it contain values like a=['10100011' '11000111' 00010111' 11100011 ']; I want to apply xor operation ; I used setxor. I want to xor first value of array i.e 10100011 to all values of cell arrays,required input & output is as follows !…
Rida
  • 21
  • 1
  • 6
-1
votes
1 answer

How to return the index of a cell which holds the largest valued element of a given column

Lets say we have Q cells, and each cell holds a N x M array. Where Array{q}(n,m) is the element in the nth row of the mth column of the qth cell. I want to find the index of the cell that holds the greatest value element in each column. Can anyone…
-1
votes
1 answer

How to build a cell-array or matrix of different dimension

I'm using the findpeaks method in Matlab to find peaks. I have a matrix(Peak) of 260x601 where its 260 different trials over 601 time points. I have a separate vector for the actual time (called TimeVec). I'm using a for loop to loop over the…
Ted Mosby
  • 1,426
  • 1
  • 16
  • 41
-1
votes
1 answer

How to re-concatenate a matrix into small matrices after some operations?

Take for exapmle cell array A {1x100}. Each cell in A is an image Mx5000. e.g. A{1,1} is 420x5000, A{1,2} is 400x5000,.... A{1,100} is 700x5000. when I concatenate all the cells vertically, I get a Nx5000 MATRIX B. After doing an operetion, the…
Xio
  • 39
  • 6
-1
votes
1 answer

Sorting Cell Array in Matlab

I have a cell array 5x1 contains directories of 5 image files like: C:\Program Files\file1.jpg C:\Program Files\file5.jpg C:\Program Files\file2.jpg and so on The order of the files is missed up. How can I sort this cell array? for…
Dani
  • 41
  • 1
  • 5
-1
votes
1 answer

Create matrices from strings in a cell-array

I have a string S1='ACD'. I generate the matrix based on the S1 as follows: fullSeq = 'ABCD'; idx = find(fullSeq == setdiff(fullSeq, 'ACD')); % it is OK M(:,idx) = 0.5 M(idx,:) = 0.5 M(logical(eye(4))) = 0.5 The output is OK: M = 0.5000 …
kgk
  • 649
  • 1
  • 10
  • 23
-1
votes
1 answer

How to convert a cell array of struct to a cell array

I have a cell array of such: data{1}.field1 = [1 2 3 4 5 6]; data{2}.field1 = [7 8 9 10]; ... data{1}.field2 = {[1 2 3]; [4 5 6]}; data{2}.field2 = {[7 8 9]}; ... I there a simple trick to convert that so I have: field1 = {[1 2 3 4 5 6], [7 8 9…
gregswiss
  • 1,456
  • 9
  • 20
-1
votes
3 answers

Pad cell array with whitespace and rearrange

I have a 2D cell-array (A = 2x3) containing numerical vectors of unequal length, in this form: 1x3 1x4 1x2 1x7 1x8 1x3 *Size of A (in both dimensions) can be variable I want to pad each vector with whitespace {' '} to equalise their lengths to…
AnnaSchumann
  • 1,261
  • 10
  • 22
-1
votes
2 answers

Matrix manipulation to extract certain sub columns: reverse idea

I have a matrix M and a cell X as shown below. A contains unique column vectors of M(1:3,:). A is introduced only to explain what I want, this is not an initial data. I try to modify the program below so that instead of finding the column vectors of…
bzak
  • 563
  • 1
  • 8
  • 21
-1
votes
1 answer

How to store results created into a cell array during a multiple for loop into a 3d array? In Matlab

In Matlab, at the end of three different for loops (for a=1:240,b=1:5 and c=1:3), I generate a {1,3} cell array where each cell contains a (1,5) array that reports only the last result of the 240 iterations. How can I generate, apart of this cell…
-1
votes
1 answer

mapping keys and values from a cell array of strings

My Data comes back from a database query into matlab as the following: {10000 by 1 cell} [10000 by 1 double] [10000 by 1 double] [10000 by 1 double] [10000 by 1 double] The first element is a bunch of sharecodes - (not unique, some repeat) The…
user2126062
  • 111
  • 11
-1
votes
1 answer

cell() constructor is not supported for code generation

When I use matlab function block in Simulink. I use another matlab function which contains cell type. But simulink reported error message because of cell. How to avoid this? I'm kind of don't want modify the function because all my functions have…
Pu Zhao
  • 11
  • 3
-1
votes
1 answer

Converting a list of indices of a cell array

I have an array x: x = [2, 1, 2, 3, 3, 2] I also have a cell array y: y = {'alpha', 'beta', 'gamma'} In fact, x is a list of indices, where each indicates an element in y. I now want to create another cell array z, where each index in x is…
Karnivaurus
  • 22,823
  • 57
  • 147
  • 247
-1
votes
1 answer

Convert large matrix to Cell Array With labels

I have a matrix that contains numerical data. Size being 31x48. I am wanting to add a label to each row of this matrix. The best way i can think of is to convert my matrix to a cell array with each row containing my 48 pieces of data. I am unsure…
-1
votes
2 answers

Remove elements from first cell array according to another

I've two cell arrays. I need to remove elemtents from the first cell array according to another: C = {'A1', 'A2', 'A3', 'A4', 'A5', 'A6'} B = { 'A2','A5'}; I want to get this result: C = {'A1', 'A3', 'A4', 'A6'} I tried this but doesn't work C =…
TimeIsNear
  • 711
  • 4
  • 19
  • 38
1 2 3
68
69