Split or extract a part of the data in a cell

64 ビュー (過去 30 日間)
greta di fusco
greta di fusco 2016 年 2 月 22 日
コメント済み: Guillaume 2016 年 2 月 25 日
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?

回答 (2 件)

Guillaume
Guillaume 2016 年 2 月 25 日
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 2016 年 2 月 25 日
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
A[I]=data{I}(:,1:length(data{I})/4);
end
Regards,
Arnab
  1 件のコメント
Guillaume
Guillaume 2016 年 2 月 25 日
The gist of the idea is there, but I'd like to point out that:
A[I]
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
data{I}(:,1:length(data{I})/4)
can be simplified to
data{I}(1:numel(data{I})/4) %and numel is a lot safer than length

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by