Creating a variable with if statement

3 次查看(过去 30 天)
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!

采纳的回答

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

更多回答(1 个)

jmac
jmac 2020-6-3
编辑:jmac 2020-6-3
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 个评论
madhan ravi
madhan ravi 2020-6-3
编辑:madhan ravi 2020-6-3
Joao not a problem;), didn’t mean it in a rude way. Thought it was OP but then realised it’s a different person, sorry! And Ofcourse you’re edited answer is the way to go.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by