Omit marker NaN data

10 vues (au cours des 30 derniers jours)
Arvind Venkatraman
Arvind Venkatraman le 30 Mar 2022
Réponse apportée : Voss le 30 Mar 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 commentaires
KSSV
KSSV le 30 Mar 2022
Read about isnan.
Walter Roberson
Walter Roberson le 30 Mar 2022
rmmissing()

Connectez-vous pour commenter.

Réponses (1)

Voss
Voss le 30 Mar 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]

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by