How to do some calculations on nonzero nonNAN elements of an array

조회 수: 3 (최근 30일)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019년 12월 2일
댓글: Tiago Dias 2019년 12월 3일
I have an array of about 400*20 size and some of its members are NAN or zero. There is a second array of the same size which I need to divide the first array by corrsponding member of the second array: FirstArrayName./SecondArrayName
how can I exclude non zero non NAN elements from this calculation?
  댓글 수: 3
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 12월 2일
편집: KALYAN ACHARJYA 2019년 12월 2일
how can I exclude non zero non NAN elements from this calculation?
Are you want exclude zero or NaN or both?
There is no impact, if you divide directly without excluding the NaN and zero elements. NaN position reflects the NaN again and zero reflects the same zero, in addition you can suppress those elements in the result array also.
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019년 12월 2일
For some reason, I need to divide the members that are nonzero and are not NAN.

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

답변 (1개)

Tiago Dias
Tiago Dias 2019년 12월 2일
Hello, is this what u want to do?
A = [1 NaN 2 NaN;3 1 4 5]
result = A(1,:) ./ A(2,:)
result =
0.3333 NaN 0.5000 NaN
  댓글 수: 2
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019년 12월 2일
Hi Thanks. There TWO separate arrays witht the same number of colmuns and row. I need to dvide them like this: array1./array2 so each member of array1 is divided by corresponding member of array 2. I want to this division to be done for non zero and non-NAN members of array1.
Tiago Dias
Tiago Dias 2019년 12월 3일
Could you provide a sample of your data? and the result you expect?

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by