how to get the content of cell array

8 views (last 30 days)
neamah al-naffakh
neamah al-naffakh on 9 May 2017
Commented: Jan on 10 May 2017
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!

Answers (2)

Matt J
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
  2 Comments
neamah al-naffakh
neamah al-naffakh on 9 May 2017
no i have did some code to extract the data from two different files and then i mixed them! thanks

Sign in to comment.


Jan
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
Jan
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?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!