how to get the content of cell array
3 views (last 30 days)
Show older comments
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!
0 Comments
Answers (2)
Matt J
on 9 May 2017
Edited: Matt J
on 9 May 2017
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
Jan
on 9 May 2017
Edited: Jan
on 9 May 2017
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 Comments
Matt J
on 9 May 2017
Edited: Matt J
on 9 May 2017
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
on 10 May 2017
@neamah al-naffakh:
x = dataBig2{1}(:,:);
is the same as
x = dataBig2{1};
So what's wrong with using dataBig2{1} directly?
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!