Omit marker NaN data

11 Ansichten (letzte 30 Tage)
Arvind Venkatraman
Arvind Venkatraman am 30 Mär. 2022
Beantwortet: Voss am 30 Mär. 2022
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 Kommentare
KSSV
KSSV am 30 Mär. 2022
Read about isnan.
Walter Roberson
Walter Roberson am 30 Mär. 2022
rmmissing()

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Voss
Voss am 30 Mär. 2022
a = struct('LANK',[NaN(260,3); rand(558,3)],'LGTRO',[NaN(260,3); rand(558,3)])
a = struct with fields:
LANK: [818×3 double] LGTRO: [818×3 double]
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
a = struct with fields:
LANK: [558×3 double] LGTRO: [558×3 double]

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by