how to get the content of cell array
4 ビュー (過去 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!
0 件のコメント
回答 (2 件)
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
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
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
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 Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!