how to get the content of cell array

3 次查看(过去 30 天)
I have an array called (dataBig2) that contains 20234 cells.
Each cell contains N number of rows and 9 columns (the first 7 columns are integer and the last 2 are 'string'). please see the attached image.
I'd like to obtain the content of each cell and store it .
for example, I have used this line of code to get the content of the first cell (i.e., 30*9) from dataBig2
x=dataBig2{1}(:,:);
by using the above line of code I was able to get the content of the first cell but I want to store the content of the remaining cells because I have 20234 cells inside the array Bigdata2
I hope that make sense!
thank you very much in advance!

回答(2 个)

Matt J
Matt J 2017-5-9
编辑:Matt J 2017-5-9
I would probably split the contents into numeric and string parts
for i=1:size(dataBig2,2)
numpart(:,:,i)=cell2mat( dataBig2{i}(:,1:7) );
stringpart(:,:,i)= dataBig2{i}(:,8:9)
end
  2 个评论
Matt J
Matt J 2017-5-9
编辑:Matt J 2017-5-9
Incidentally, if dataBig came from xlsread, you could have read the numeric data and text into separate arrays using the syntax,
[num,txt] = xlsread(___)
neamah al-naffakh
no i have did some code to extract the data from two different files and then i mixed them! thanks

请先登录,再进行评论。


Jan
Jan 2017-5-9
编辑:Jan 2017-5-9
What do you want exactly? val{k} contains the contents of the first cell. It does not matter, if you copy the cell dataBig2 to the cell final, because this changes the name of the variable only.
Do you want to get the numerical values as matrices?
value = cell(1, numel(dazaBig2);
info = cell(1, numel(dazaBig2);
for k = 1:numel(dataBig2)
s = size(dataBig{k}, 2);
value{k} = cell2mat(dataBig2{k}(:, 1:s-2));
info{k} = dataBig2{k}(:, s-1:s);
end
The trailing columns containing strings cannot be included in the numerical matrices, but it is stored separately. I'm not sure if this is useful.
  3 个评论
Matt J
Matt J 2017-5-9
编辑:Matt J 2017-5-9
I want to get the content of each cell array and store it!
But how is that different from what you already have? Each of the 20234 data sets is already "stored" in Bigdata2{i} and indexing operations Bigdata2{i}{j,k} are already available to let you "get" any particular cell inside that.
If you are saying that you want the data to be indexed differently, then describe what that indexing operation will look like.
Jan
Jan 2017-5-10
@neamah al-naffakh:
x = dataBig2{1}(:,:);
is the same as
x = dataBig2{1};
So what's wrong with using dataBig2{1} directly?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by