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

converting a 2d cell matrix into a 2d numerical matrix

I am new to MATLAB and was confused about how to obtain numeric arrays from cell arrays. According to MATLAB, I have some matrix result and I get the following: >> size(result) ans = 1 15 >> result ans = Columns 1 through 15 [3] …
TakeS
  • 616
  • 1
  • 7
  • 14
0
votes
2 answers

how to write cell array to text file MATLAB, error with dlmwrite

I understand that this is a recurrent topic, I have tried understanding the answers that people provided but none of them seemed easy to transfer to my particular problem as the solutions are usually for an implementation that is too far from what…
Bastien
  • 362
  • 2
  • 7
  • 21
0
votes
1 answer

Find last consecutive appearance in cell array

I have a cell array that looks like the following: Tickerarray = 'MNST' 'MNST' 'MNST' 'ALGN' 'ALGN' 'GRA' 'VLO' 'GRA' 'SKS' 'SKS' 'VLO' 'GRA' 'SKS' 'TSO' 'JDSU' 'TSO' 'TSO' 'TSO' 'VLO' …
0
votes
1 answer

for loop with cell array

I'm new to MATLAB and I'm having problem with a for loop in a cell array. I have a 52x52 cell array B. In every cell, there is a 51x51 matrix. For every cell of the first row of B, I want to calculate the trace and I want the trace-elements in a…
Ben
  • 3
  • 1
0
votes
0 answers

MATLAB feedforwardnet

I am still new in using MATLAB. I am trying to create a feed-forward neural network with MATLAB custom function feedforwardnet, I got my own training set with dimension 2 x 100, which is a multiple-input array. Now I ran into the problem of how to…
Charly H.
  • 83
  • 5
0
votes
1 answer

Check if a special row in a cell array exists in MATLAB or not

Please i need help but it's a little hard for me to declare it correctly in English,please be patient with me. I've got a cell array which for example has 10 rows and 10 columns. I fill each rows of the cell array in a loop(for) and there is this…
SaraDean
  • 169
  • 1
  • 13
0
votes
1 answer

How to display with n decimal places from cell array that also contain strings in matlab

Hello I have a cell array that contains numbers, and also strings. I want to print the cell array so that I will see only 5 number after the decimal point, the strings need to be the same Example: for i=1:3 c{1,i*2-1} = pi c{2,i*2-1} = pi/2 …
Oren
  • 4,711
  • 4
  • 37
  • 63
0
votes
3 answers

How to display formatted numbers from a cell array with n decimal places

I have a cell array that contains both numbers and strings. I want to print the cell array so that I will see only 5 numbers after the decimal point. For example: c{1, 1} = pi; c{2, 1} = pi / 2; c{3, 1} = pi / 4; c{4, 1} = 2 ^ 0.5; After using…
Oren
  • 4,711
  • 4
  • 37
  • 63
0
votes
3 answers

How to perform logical indexing of cell array for sparse matrix in coordinate format?

Let A be a sparse matrix in coordinate format [row(int) col(int) val(float)]. If a upper triangular sparse matrix of A is needed, then the same can be obtained using logical indexing like: A = A(A(:,1) <= A(:,2), :); If A is cell array [{row(int)}…
Stoka
  • 39
  • 7
0
votes
1 answer

Matlab - vectorized way to indices in cell array equal string

I have a 435x1 cell array whose elements are either 'y', 'n', or '?'. I want to find which indices are equal to 'y'. With normal arrays, I just use the find function. But I can't use that with cell arrays because eq is not defined for type cell. I…
Sterling
  • 3,835
  • 14
  • 48
  • 73
0
votes
1 answer

Saving Images in Cell Array (Matlab) into different files

I have a 1x7049 Cell Array. Each of the elements of this array is a 96x96 matrix. Now, I want to save each of these 96x96 matrices into jpg files, so that I will get 7049 images. How can I do this?
Sharath Chandra
  • 89
  • 1
  • 1
  • 9
0
votes
2 answers

MATLAB Cell Array - Average two values if another column matches

I have a cell array in which some of the entries have two data points. I want to average the two data points if the data were collected on the same day. The first column of cell array 'site' is the date. The fourth column is the data concentration.…
SugaKookie
  • 780
  • 2
  • 17
  • 41
0
votes
2 answers

Find Date Range Rows and Extract

This should be straight-forward in MATLAB I just don't know how and am stuck. I have data that looks like this below that is in the form: mm/dd/yyyy hh:mm windspeed - this is hourly data spanning years from 1991 up to the present (2013) of cell…
user2100039
  • 1,280
  • 2
  • 16
  • 31
0
votes
2 answers

Attempting to create cell array from individual string values, receive subscript indices must be either positive integers or logicals..?

Here is my code %This function takes an array of 128Bvalue numbers and returns the equivalent binary %values in a string phrase function [PhrasePattern] = GetPatternForValuesFinal(BarcodeNumberValues) load code128B.mat; Pattern = {}; …
user2780519
  • 93
  • 1
  • 2
  • 8
0
votes
2 answers

Matlab: how to use numeric arrays such as 1:2 to create a cell array such as {1,2}?

I want to use the numeric array such as 1:7 to create a cell array such as {1,2,3,4,5,6,7}. How can I do it? By which function? Wrong >> {1:2} ans = [1x2 double] Correct output >> {1,2} ans = [1] [2]
hhh
  • 50,788
  • 62
  • 179
  • 282