removing NaN values from mat file

조회 수: 7 (최근 30일)
kH
kH 2019년 10월 10일
편집: Stephen23 2019년 10월 11일
I have mat file with 6778 x1 variables(signals ) but in some variables NaN value in the row must be delete .
How to check the NaN values in the mat file and delete the rows of the NaN values ?
  댓글 수: 2
kH
kH 2019년 10월 11일
Eg :
X.mat file contains 600x1 varibles (signals)
Let
field values dimension
signal 1 [NaN ;NaN;0;0;0] 5x1
signal 2 [NaN ;NaN;3;0;5] 5x1
signal 3 [NaN ;NaN;0;3;0] 5x1
signal 4 [NaN ;NaN;2;0;0;9;8] 7x1
signal 5 [NaN ;NaN;0;1;0] 5x1
signal 6 [NaN ;NaN;0;0;6] 5x1
output :
signal 1 [0;0;0] 3x1
signal 2 [3;0;5] 3x1
signal 3 [0;3;0] 3x1
signal 4 [2;0;0;9;8] 5x1
signal 5 [ 0;1;0] 3x1
signal 6 [0;0;6] 3x1
how to obtain the above output ?
Stephen23
Stephen23 2019년 10월 11일
편집: Stephen23 2019년 10월 11일
"I have mat file with 6778 x1 variables..."
This is not clear: does the .mat file contain:
  • 6778 separate variables (of unknown size), or
  • 1 variable of size 6778x1 ?

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2019년 10월 11일
편집: Stephen23 2019년 10월 11일
load into an output variable (which is a scalar structure), then loop over the fields:
For example:
S = load('NameOfYourFile.mat');
C = fieldnames(S);
for k = 1:numel(C)
M = S.(C{k});
M(isnan(M)) = [];
S.(C{k}) = M;
end
If required, save again using the -struct option:
save('NameOfNewFile.mat','-struct','S')

추가 답변 (1개)

Rik
Rik 2019년 10월 10일
A(isnan(A))=[];
  댓글 수: 1
kH
kH 2019년 10월 11일
But how to do it for complete Mat file . This method works for indiviual varibles only .

댓글을 달려면 로그인하십시오.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by