Parsing a cell array

조회 수: 12 (최근 30일)
R J
R J 2014년 9월 11일
댓글: R J 2014년 9월 11일
Hi there,
I have a 24x4 cell called "Data" where each cell contains an array of 2x2000 double. I would like to parse the cell in the following way:
- The 1x2000 double in cell in Data{1,1}(1,:), Data{1,2}(1,:), Data{1,3}(1,:), and Data{1,4}(1,:) are all parsed into its in own "temp" array so that "temp(:,:)" contains all 4 1x2000 doubles from those 4 cells. The plan is to use a loop so that I can parse the entire 24x4 cell in this way.
Any help would be appreciated.. Thank you!

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 9월 11일
Since any element of your 24x4 cell is a 2x2000 array of doubles, then you could just use an inner loop to populate the temp array with the first row of each of those 2x2000 arrays. Something like
% pre-allocate memory to temp
temp = zeros(4,2000);
% iterate over each of the 24 rows
for u=1:size(Data,1)
% iterate over each of the 4 columns
for v=1:size(Data,2)
temp(v,:) = Data{u,v}(1,:);
end
% do stuff with temp
end
The above should allow you to parse all the necessary data into the temp array so that you can do some further processing. If you want to save temp from each iteration, then you could just copy it to a three-dimensional matrix or to another cell array at each iteration of u.
  댓글 수: 1
R J
R J 2014년 9월 11일
Thanks Geoff!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 9월 11일
temp = permute(cell2mat(permute(Data,[1,3,2])),[3,2,1]);
  댓글 수: 1
R J
R J 2014년 9월 11일
Thank you Andrei!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by