Transferring/Copying Data between Cell Arrays, Skip NaN values: Updated Code

조회 수: 3 (최근 30일)
ErikaZ
ErikaZ 2019년 2월 28일
답변: ErikaZ 2019년 2월 28일
I have the following code
for i = [1 10 100 2 20 200 3 30 300 4 40 400 5 50 500 6 60 600 7 70 700 8 80 800]
[row,col]=cellfun(@(s) find(s==i),gait_events_cut_inter,'uni',false);
%row = cellfun(@(s) round(mean(s)),row,'uni',false);
%or
row = cell2mat(cellfun(@(s) round(mean(s)),row,'uni',false));
order = floor(single(log(i)./log(10)));
if order==2
i=i/100;
e=3;
elseif order ==1
i=i/10;
e=2;
else
i=i;
e=1;
end
for j=1:3
gait_events_inter{j}{i,1}(e,1)=row(j);
end
end
Everything works up to saving the data in gait_events_inter. So, I have roww with 3 values (either as an array or cell array - what ever makes the transfering easier) and I was able to copy those 3 values to the corresping outernested cell 1,2,3, on the innernested cell on row i and row e in the innermost array to create a cell array similar to:
  • But, there will be some cases like row 2 or 7 in the image, where roww will be NaN for the higher order i, but in those cases, I do not want to transfer the NaN values. How do I check for that? I was thinking of using e, if higher than 1, and NaN, to skip (contine).

채택된 답변

ErikaZ
ErikaZ 2019년 2월 28일
for i = [1 10 100 2 20 200 3 30 300 4 40 400 5 50 500 6 60 600 7 70 700 8 80 800]
[row,col]=cellfun(@(s) find(s==i),gait_events_cut_inter,'uni',false);
%row = cellfun(@(s) round(mean(s)),row,'uni',false);
%or
row = cell2mat(cellfun(@(s) round(mean(s)),row,'uni',false));
order = floor(single(log(i)./log(10)));
if order==2
i=i/100;
e=3;
elseif order ==1
i=i/10;
e=2;
else
i=i;
e=1;
end
for j=1:3
if e>1 & isnan(row(j))
continue
else
gait_events_inter{j}{i,1}(e,1)=row(j);
end
end

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by