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

In matlab is cell array of cell arrays equivalent to list of list

I'm trying to implement functionality in matlab where I need the equivalent data structure to a list of lists. Based on what I have found is a cell array of cell arrays a good equivalent in matlab. Thanks.
user1172468
  • 5,306
  • 6
  • 35
  • 62
-1
votes
1 answer

How to copy cell to array in Matlab

Alright let me explain detailed my question this below image is displaying my matrix where i want to copy my data Alright now what i want to do that is as you can see 1x4 cell i want to copy it as an array to another variable such as …
Furkan Gözükara
  • 22,964
  • 77
  • 205
  • 342
-2
votes
1 answer

MATLAB: Replace a row/column in a cell array with NaN

How am I supposed to replace a complete row/column within a cell array with NaNs? test = cell(3,2); % These calls won't do it test{2,:} = nan; test(2,:) = nan;
Andi
  • 3,196
  • 2
  • 24
  • 44
-2
votes
1 answer

Python , create Matlab's like Dynamic cell array

hello I should translate the following matlab code in python, it use dynamic cell array: NUM=zeros(size(CELLin)); NUM=NUM(:); jALL=cell(0,0); r=0; for k=1:size(CELLin,1) r=r+1; NUM(r)=(numel(CELLin{k,1})-1)/2; % Ak NoptN …
Linux
  • 39
  • 7
-2
votes
1 answer

Cell array to matrix conversion in matlab

I would like to covert three <1xN cell> (A, B and C) into a single Nx3 matrix. Could someone help me with this? C={{1xN}; {1xN}; {1xN}}; where each N is a number in single quotes, e.g. C = {{'123123' ,'12324', ....N times}; {'123123', '12324',…
EyesOfÖzil
  • 309
  • 1
  • 9
-2
votes
1 answer

Why Matlab does not save the partial results of my loop in a cell array?

My code is something like: for i=1:n a=something; b=something; c=cell(n,1); c{i,1}=[a b]; end Where a and b are both a 1x3 matrix. When I execute the loop Matlab saves only the result of the last iteration in the last cell. What am I…
-2
votes
1 answer

Change order of characters in each string in a cell array

I have a cell array which contains strings like this : Input = { 'BDCE'; 'BAFD'; 'HGAB' } How can I change order of characters in each string in a cell array? The order is from 'A' to 'Z' The expected output should be like this : Output =…
kgk
  • 649
  • 1
  • 10
  • 23
-2
votes
1 answer

get number of levels of a cell

Well i got the problem, that i have to acces the content of a cell in Matlab. But it's not an ordinary cell. There could be a cell in a cell. And i don't know how many levels the first cell has. All the cells have the dimension (1,x) so it could be…
-2
votes
1 answer

access and create new array from the array cell of struct

In file .mat in matlab,there is an array cell 'channels' 1x1 struct. I want to create a new array which only contains ['LAG_01' 'LAG_02' ... 'LPG_12']. Is there any method to do that ? Thanks, channels ans = X.LAG_01.: 'LAG_01' X.LAG_02.:…
Duc Vu
  • 141
  • 1
  • 6
-2
votes
2 answers

Scramble the positions of a cell array

I have two cell array as follows Z= (2,5) (2,3) (2,1) (2,2) (2,4) (4,5) (4,3) (4,1) (4,2) (4,4) (5,5) (5,3) (5,1) (5,2) (5,4) (3,5) (3,3) (3,1) (3,2) (3,4) (1,5) (1,3) (1,1) (1,2) (1,4) W= 'ATGC' 'ACTG' 'AGCT' 'AATT' 'TATG' …
-3
votes
2 answers

creating this specific cell array in MATLAB

I want to create this particular cell array. I don't want to do it manually, a = {'1. ','2. ','3. ','4. ', ........upto length(txt)} I thought of create initially numbers with 1:length(txt) and append it to '.' to create cell array a, But I am…
Adupa Vasista
  • 71
  • 1
  • 12
-3
votes
1 answer

MATLAB how to apply a function to cell arrays

I have the following cell array: <20x2> <32x2> <28x2> <30x2> What I am trying to do is read into row 1 of the cell array which is <20x2> and once I am in <20x2> I would like to apply the following function to the first column only. In the first…
user3536870
  • 249
  • 1
  • 2
  • 13
-3
votes
1 answer

Swapping half of array elements with half of another array

I want to swap half of the elements of an array A with corresponding half of elements of another array B.Is there any built-in function for this operation or is there any shortcut ???Can anyone help me ???? k=1; for i=1:nwpc for j=i+1:nwpc …
lara
  • 63
  • 7
-3
votes
1 answer

Matlab - Cell arrays and giving variable name with different indexes

I'm trying to make a for-loop in matlab that would return the following: C_1 = 0 C_2 = 0 C_3 = 0 C_4 = 0 C_5 = 0 But, before that, I want also a value as follows: C_0 = 0. I gave it a try as follows but didn't work: function test C{0} = 0; …
Simplicity
  • 47,404
  • 98
  • 256
  • 385
-4
votes
1 answer

Matlab - Why ismember does not work?

I have a cell vector with different & redundant company names. And a list of interesting companies. I try to figure out, where in the big matrix the interesting companies appear. I am interested in all appearances. My Code for some reason does not…
Ilja
  • 611
  • 3
  • 9
  • 19
1 2 3
68
69