필터 지우기
필터 지우기

Removing/clearing NaN/0 values from matrix/array data

조회 수: 4 (최근 30일)
drb17135
drb17135 2021년 3월 9일
답변: Mehmed Saad 2021년 3월 9일
Hi,
So I have two - 8640x1 arrays of data
  • one represents wind speed every 5 minutes over a month
  • the other represents rain intensity every 5 minutes over the same month
I have a function that loops these values into a series of calculations. However, the code is not wokring for some of it. I believe this is down to one of the functions I am using can not have a 0 input.
Therefore I need to clear my data of 0 values.
I know how to do this for an indivdual array such as
B = A(A~=0)
However, imagine my data set was
A =
A = [0;9;6;4;3];
B = [1;3;4;0;0];
I need it so that when there is a 0 value in B, the corresponding row in A must also be removed even if there is a value for this.
So that my final value arrays looks like such :
A = [9;6];
B = [3;4];
Hope that makes sense.
Thanks:)

답변 (2개)

Sargondjani
Sargondjani 2021년 3월 9일
A1 = A(A~=0 & B~=0) should work

Mehmed Saad
Mehmed Saad 2021년 3월 9일
A = [0;9;6;4;3];iA = A~=0;
B = [1;3;4;0;0];iB = B~=0;
ind = iA&iB;
A = A(ind)
B = B(ind)
A =
9
6
B =
3
4

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by