Using 1s and 0s to change data to NaN

1 Ansicht (letzte 30 Tage)
Robert
Robert am 14 Jul. 2015
Kommentiert: Robert am 14 Jul. 2015
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

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by