필터 지우기
필터 지우기

Creating a variable with if statement

조회 수: 3 (최근 30일)
JB
JB 2020년 6월 3일
댓글: JB 2020년 6월 4일
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.
JB
JB 2020년 6월 4일
Thank you as well!

댓글을 달려면 로그인하십시오.

카테고리

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