Split or extract a part of the data in a cell

107 views (last 30 days)
greta di fusco
greta di fusco on 22 Feb 2016
Commented: Guillaume on 25 Feb 2016
Starting from a cell called "data" sized 17x1, containing each one 1x1487040 double
i would be able to extract the first 1/4 of the content from the 9th to the 14th cells obtaining a matrix of double.
The problem arises because i usually have huge lengths for the double numbers in the cell, so that if i first use cell2mat (with the intention of splitting the array after) an out of memory error comes up.
It is possible to split a cell of double without cell2mat?

Answers (2)

Guillaume on 25 Feb 2016
An alternative to Arnab's answer, using cellfun:
A = cell2mat(cellfun(@(v) v(1:numel(v)/4), data.data(9:14), 'UniformOutput', false))

Arnab Sen
Arnab Sen on 25 Feb 2016
Hi greta,
My understanding is that you would like to extract a part of cell from a cell array. You can directly access the cell of the cell array without converting the whole cell array to matrix. As an example, if you want to extract the first 1/4th content from 9th cell, you can do something link below:
>> A=data{9}(:,1:length(data{9})/4);
You can use a for loop to extract from multiple cell. Something like
>>for I=9:14
  1 Comment
Guillaume on 25 Feb 2016
The gist of the idea is there, but I'd like to point out that:
is not valid matlab syntax. At the very least, it should be
A(I, :)
And A should be predeclared before the loop.
Secondly, since the content of the cells are all vector, 2d indexing is not required so
can be simplified to
data{I}(1:numel(data{I})/4) %and numel is a lot safer than length

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by