Creating a variable with if statement

3 visualizaciones (últimos 30 días)
JB
JB el 3 de Jun. de 2020
Comentada: JB el 4 de Jun. de 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!

Respuesta aceptada

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

Más respuestas (1)

jmac
jmac el 3 de Jun. de 2020
Editada: jmac el 3 de Jun. de 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 comentarios
madhan ravi
madhan ravi el 3 de Jun. de 2020
Editada: madhan ravi el 3 de Jun. de 2020
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.
JB
JB el 4 de Jun. de 2020
Thank you as well!

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by