Creating a variable with if statement

5 views (last 30 days)
JB
JB on 3 Jun 2020
Commented: JB on 4 Jun 2020
Hi... I'm struggling with this for hours...
Suppose there is a column vector X:
1
5
7
8
9
4
2
.
.
.
and I would like to create another vector, Y, such that X < 6 but keep the order:
1
5
missing
missing
missing
missing
4
2
.
.
.
Please help. Thank you!

Accepted Answer

madhan ravi
madhan ravi on 3 Jun 2020
y = num2cell(x);
y(x>6) = {'missing'}

More Answers (1)

jmac
jmac on 3 Jun 2020
Edited: jmac on 3 Jun 2020
Just eliminate the entries you don't want: y=x; y(y>=6)=[];
Or, if you want to maintain the size and class (vector), NaN: y=x; y(y>=6)=NaN;
  4 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!