Delete value bigger than & smaller than, in a for loop

조회 수: 4 (최근 30일)
sprklspring
sprklspring 2018년 9월 18일
편집: KALYAN ACHARJYA 2018년 9월 18일
I am trying to get rid off all of the values of the vector n=1:5000 that are smaller than number value 1000 and bigger than number 2000. This is my code, which of course is not working properly:
for k=1:length(MUPS)
for s=1:length(MUPS{k})
if MUPS{k}(MUPS{k}<1000) & MUPS{k}(MUPS{k}>2000)
MUPS{k}(s) = [];
else
MUPS{k}(s) = MUPS{k}(s);
end
end
end
I need to use the remainings of the vector later on in the code. Could you tell me what am I doing wrong?

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 9월 18일
편집: KALYAN ACHARJYA 2018년 9월 18일
Get rid of multiple for loops, you can do the same by following a single line.
new_vector=n(n>1000 & n<20000);
See the following simple example for your reference-
  댓글 수: 2
sprklspring
sprklspring 2018년 9월 18일
Thanks!
KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 9월 18일
편집: KALYAN ACHARJYA 2018년 9월 18일
My Pleasure
Happy to Help You!
Regards

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by