Using 1s and 0s to change data to NaN

조회 수: 1 (최근 30일)
Robert
Robert 2015년 7월 14일
댓글: Robert 2015년 7월 14일
Suppose I have 2 arrays
A = [1,2,3,4,5,6,7,8]
B = [0,1,1,0,1,0,0,1]
I only want to keep the numbers that match 1s in a second array and turn 0s to NaN, So the output should be
C = [Nan,2,3,NaN,5,NaN,NaN,8]
Is there a way to do this?
The actual situation I want to apply it to has much more data but I assume the concept will be transferrable

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 14일
A = [1,2,3,4,5,6,7,8]
B = [0,1,1,0,1,0,0,1]
C=A;
C(~B)=nan

추가 답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by