Omit marker NaN data

12 visualizaciones (últimos 30 días)
Arvind Venkatraman
Arvind Venkatraman el 30 de Mzo. de 2022
Respondida: Voss el 30 de Mzo. de 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 comentarios
KSSV
KSSV el 30 de Mzo. de 2022
Read about isnan.
Walter Roberson
Walter Roberson el 30 de Mzo. de 2022
rmmissing()

Iniciar sesión para comentar.

Respuestas (1)

Voss
Voss el 30 de Mzo. de 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]

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by