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

Reshape MxN cell array to 1x(M*N) cell array MATLAB

I am trying to make a cell array for legend titles in a plot. The plot has repetitions of an experiment with different frequencies and 3 different sensors. I need a different colour for each different sensor and frequency. Hence in the following…
phujeb
  • 1
  • 1
0
votes
0 answers

Exporting cell array with both text and numbers to csv file in Matlab

I have a cell array with nine columns (the first eight text and the ninth numbers) and thousands of rows that I would like to export to a csv file. I have tried to follow the suggestions provided in similar questions and I take that the best way to…
aulky11
  • 79
  • 6
0
votes
1 answer

Moving rows from a matrix to a cell array using matlab: Trouble indexing cells

Using matlab, I am attempting to move rows from one matrix (RF) to a cell array using equivalent values in the matrix and the array. For each value i in the first column of matrix RF I would like to find which cell contains the same value. I would…
Dinah
  • 3
  • 2
0
votes
1 answer

Creating a structure point and then calculating distance between two points

I need some help figuring how do i create a structure point. I need two fields x and y then I want to create a function that calculates the distance between these two points. What I have right now is: function [ out ] = pointDist3( pointpair1,…
Venom
  • 27
  • 7
0
votes
1 answer

Matlab making new cell array from another cell array fileds

I have a cell array thiscells: thiscells <1*40 cell> eacharray of thiscells is 280*3 I have a function (TheFunction) that gets input of cell array that each array is X*2 How can I send a cell array to TheFunction that contain only columns1,3 from…
JohnnyF
  • 1,053
  • 4
  • 16
  • 31
0
votes
1 answer

Removing rows in a cell array without a specific word

I have a cell array in MATLAB with majority of rows containing the word sentiment and these are the only ones relevant to my algorithm. However, some rows do not contain the word 'sentiment', so I wish to removed these. Could anyone provide a…
Adam
  • 93
  • 1
  • 1
  • 9
0
votes
1 answer

MATLAB cell array - strange behaviour with find in cell array

I have a cell array in MATLAB that's behaving quite strangely. I have 104 single row vectors I've stored as cells, ranging from 80 to 344 elements. As a result, I have a 104 x 344 cell array, called z. Each element has a single numeric value in it.…
DRG
  • 241
  • 1
  • 6
0
votes
1 answer

Matlab: How to matrix calculation with cell matrix?

I need to calculation R*S*R'. R is an ordinary matrix. But S is composed of values. The element of S is the value of F(w), and is calculated by [PressureSpecAuto,F] = periodogram(....); S{i,j} = PressureSpecAuto; which means each element is a set…
ZK Zhao
  • 19,885
  • 47
  • 132
  • 206
0
votes
1 answer

Matlab: Loop through cell array to concatenate strings

I need to import file Degree210B49_015.dat and Degree210B50_005.dat So, I do it with cell array like this column_file_number = {'49_015' '50_005'}; for i = column_file_number Name_file= strcat('Degree210B', i, '.dat'); Name_file …
ZK Zhao
  • 19,885
  • 47
  • 132
  • 206
0
votes
1 answer

Reading a large, oddly formatted text file of data into MATLAB

Need to read a huge text file full of weirdly formatted data. The format goes like this: //Header with Title Info //Header with Test1 Info //More Test1…
jephex
  • 13
  • 5
0
votes
1 answer

Matlab How to perform substraction for multiple cell arrays?

The code below is only for 2 cell arrays, named B and C A=cellfun(@minus, B, C, 'UniformOutput', false) I want to perform a loop to be able to perform substraction for all my cell arrays. Example of B{i} and C{i} are below: B{1}=[0.435]…
Allyson
  • 115
  • 1
  • 3
  • 12
0
votes
1 answer

convert a column (of numbers) of a cell from number to string

In Matlab, I have a problem where I want to sort a cell w.r.t a column of numbers. however the sortrows function doesn't work (I get this error:Some cells in X contain non-scalar values and cannot be sorted). I suspect that I need to convert the…
0
votes
1 answer

How to loop over cell with different array size?

The following code supposed to output the content of 1st cell in combs and access to each row of the cell which is defined by bb. My issue here is that it doesn't loop over to 2nd and 3rd cell. % input arrays A=[2 1 3]; B=[4 2 1 3 3]; C=[1…
Cina
  • 9,759
  • 4
  • 20
  • 36
0
votes
3 answers

Matlab - Find index of a cell by its value

I have a cell array filedNames 11x1 in which each cell is a single string and I want to get the index of the cell which is equal to the string name. I've found this example: C = { {'a'}, {'b'}, {'c'}, {'a'}, {'a'} } % data idx = find(strcmp([C{:}],…
Konstantin
  • 396
  • 3
  • 19
0
votes
3 answers

Filtering a Cell Array with Recursion

I'm pretty close on this problem. What I have to do is filter out a cell array. The cell array can have a variety of items in it, but what I want to do is pull out the strings, using recursion. I am pretty close on this one. I just have an issue…
Jessica Marie
  • 293
  • 5
  • 16