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

Label Data for Classification in Matlab

I have 2 sets of train data, A and B with different sizes, which I want to use for training the classifier, and I have 2 labels in 2 char variables like, L1 = 'label A'; L2 = 'label B'; How can I produce appropriate labels ? I will use…
Rashid
  • 4,326
  • 2
  • 29
  • 54
0
votes
1 answer

Determining Moves and Outcomes for Tic-Tac-Toe in MATLAB W/ Helper Function

Note: I am up-dating this as I go along. I add in comments to let you know if I added in code or not. Since I have no comments, I doubt anyone will get confused. And to whomever down-voted me, I'm putting in as much information as I can. Calm…
Jessica Marie
  • 293
  • 5
  • 16
0
votes
1 answer

how do solve this error message? 'Error using image Numeric or logical matrix required for image CDate

I have the following code: tile {6} = imread ('tw.png','png'); tile {5} = imread ('twpw.png','png'); tile {4} = imread ('twpb.png','png'); tile {3} = imread ('tb.png','png'); tile {2} = imread ('tbpw.png','png'); tile {1} = imread…
Dickson tan
  • 35
  • 2
  • 8
0
votes
3 answers

DJing with MATLAB (Low-Level I/O)

Alrighty everybody, it's the time of the week where I learn how to do weird things with MATLAB. This week it's DJing. What I need to do is figure out how to make my function output the name of the song whose length is closest to the time left. For…
Jessica Marie
  • 293
  • 5
  • 16
0
votes
2 answers

How to store variable length arrays?

I want to store an array which changes its size in each iteration of a for loop. For example, for y=1:100 for x=1:50 . . ms(:,x,y) = ans; . . end end The 'ans' is a row vector which changes its size in each iteration of y. How can…
Kave
  • 1
  • 1
0
votes
2 answers

Matlab Array has strange syntax

In Matlab, we use textscan to get a cell array from a file or somewhere. But the behavior of the cell array is so strange. There is the sample code: >> str = '0.41 8.24 3.57 6.24 9.27'; >> C = textscan(str, '%3.1f %*1d'); >> C C = [5x1…
Kai
  • 191
  • 1
  • 2
  • 12
0
votes
1 answer

performing operations for the cells in MATLAB

I have the following variable: QOS= [100 200 120 300 45 88 90 500 66 180]; I have MPR that is a n x n cell. It contains some cells that are 2 x 2 double and cells that are 1 x 2 double. I want for the cells that are 2 by 2 double (for example [2…
user3685062
  • 79
  • 1
  • 1
  • 7
0
votes
2 answers

Apply functions to cell array of matrices in Matlab?

I have 3x3 cells a in Matlab, each cell containing a vector of 9x1 a=cell(3,3); for i=1:3 for j=1:3 a{i,j}=randi(10,[9 1]); end end I would like to multiply each cell of a by its transpose and then sum across cells but I don't know…
TEX
  • 2,249
  • 20
  • 43
0
votes
3 answers

Display Cells in table or text file with different dimensions in Matlab

I have a cell data type in MATLAB R2012a with different cells having different dimensions and I am having trouble displaying the results either in a table or in a text file. Both would be great. My cell looks like this 'detected' 'crane' crane'…
Austen Novis
  • 444
  • 1
  • 12
  • 30
0
votes
1 answer

Change code to fit strings - Matlab

I have the following code: NI1=[NI{:,1} NI{:,2} NI{:,3}]; [~,NI2]=sort(NI1(:,2)); NI1=NI1(NI2,:); NI1((NI1(:,3) == 0),:) = []; NI1=unique(NI1(:,1:3),'rows'); NI3= unique(NI1(:,1:2),'rows') for mj=1:size(NI3,1) NI3(mj,3)=sum(NI1(:,1) ==…
user3557054
  • 219
  • 2
  • 11
0
votes
1 answer

MATLAB: Find numeric columns in a cell array

I would like to use gplotmatrix on a dataset data, which contains mixed data (numeric and strings). However, gplotmatrix works on numeric data, so I need to convert my dataset to a matrix. As far as I know, the only way is to do this is…
DeltaIV
  • 4,773
  • 12
  • 39
  • 86
0
votes
1 answer

Apply formula on Matlab

I have this formula: 100-[(x-1)/(y-1)]*100, and I would like to apply it to a cell-type variable F with A rows * 14 columns in MATLAB, where x = F(:,14) and y = size(F,1). I have been trying to get there by different attempts, this is one example I…
user3557054
  • 219
  • 2
  • 11
0
votes
1 answer

Reordering Cell Array by Array of Indices

Suppose I have a cell array x and an integer array y: x = {'apple', 'orange', 'banana', 'pear'}; y = [2 4 3 1]; In fact, y represents indices of x. I want to now create a cell array z with the elements of x reordered as specified by the order…
Karnivaurus
  • 22,823
  • 57
  • 147
  • 247
0
votes
1 answer

Matlab: Import multiple numeric csv .txt files into single cell array

I have multiple (say N of them) .txt files consisting of numeric csv data in matrix form. I would like to import each of these data files into one (1 x N) cell array, whilst preserving the original matrix form. If the original data is small, say…
0
votes
1 answer

Iterate Matrix into a cell array

Is there a way I can write a for loop that will add a given number of matrix into a cell array. `C1 = [];` So instead of having to write everyone out like: `cell = {} cell = [cell C1]; cell = [cell C2]; cell = [cell C3]; cell = [cell C4];` Where…