Omit marker NaN data
조회 수: 10 (최근 30일)
이전 댓글 표시
Sorry I am very new to MATLAB. I have 2 truct arrays where I need to truncate NaN values from the arrays. About the first 260 rows are NaN values. How would I go about doing this?
a =
struct with fields:
LANK: [818×3 double]
LGTRO: [818×3 double]
LHEE: [818×3 double]
LKNE: [818×3 double]
LSHO: [818×3 double]
LTOE: [818×3 double]
RANK: [818×3 double]
RGTRO: [818×3 double]
RHEE: [818×3 double]
RKNE: [818×3 double]
RSHO: [818×3 double]
RTOE: [818×3 double]
STRNM: [818×3 double]
nFrame: [818×1 double]
time: [818×1 double]
b =
struct with fields:
LANK: [797×3 double]
LGTRO: [797×3 double]
LHEE: [797×3 double]
LKNE: [797×3 double]
LSHO: [797×3 double]
LTOE: [797×3 double]
RANK: [797×3 double]
RGTRO: [797×3 double]
RHEE: [797×3 double]
RKNE: [797×3 double]
RSHO: [797×3 double]
RTOE: [797×3 double]
STRNM: [797×3 double]
nFrame: [797×1 double]
time: [797×1 double]
댓글 수: 2
답변 (1개)
Voss
2022년 3월 30일
a = struct('LANK',[NaN(260,3); rand(558,3)],'LGTRO',[NaN(260,3); rand(558,3)])
f = fieldnames(a);
% go through each field of struct 'a'
for ii = 1:numel(f)
% find the index of the first row of
% field f{ii} in 'a' that is not all NaN:
idx = find(~all(isnan(a.(f{ii})),2),1);
if isempty(idx)
% no such row means field f{ii} is all NaNs -> remove the whole
% thing by treating it as if it has a row with a non-NaN value one
% row beyond its last row:
idx = size(a.(f{ii}),1)+1;
end
% remove rows up to and including row idx-1:
a.(f{ii})(1:idx-1,:) = [];
end
a
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!