필터 지우기
필터 지우기

How to get specified values in vector?

조회 수: 2 (최근 30일)
KH
KH 2013년 6월 20일
Hi,
I need some help on this.
Lets say i have a vector of: a= [1.1 1.3 1.5 1.8 2.5 3.4 6.7 6.9 8.0 10.2 15.0 17.8 21.0 23.4]
However, i only want the values of not exceeding 10 in one of my vector, which is something like that: b= [1.1 1.3 1.5 1.8 2.5 3.4 6.7 6.9 8.0]
and another vector which has values of more than 10 in it: c= [10.2 15.0 17.8 21.0 23.4]
How do i do these?
Thank you so much.

답변 (1개)

the cyclist
the cyclist 2013년 6월 20일
편집: the cyclist 2013년 6월 20일
idx = a<=10;
b = a(idx);
c = a(not(idx));
  댓글 수: 2
KH
KH 2013년 6월 20일
hi, thanks for the suggestion. actually i need to slightly modify my question.
let say my vector now is: a= [1.1 1.3 1.5 1.8 2.5 3.4 6.7 6.9 8.0 10.2 15.0 17.8 21.0 23.4 8.0 5.5],
but i still want my vector b= [1.1 1.3 1.5 1.8 2.5 3.4 6.7 6.9 8.0] while c= [10.2 15.0 17.8 21.0 23.4 8.0 5.5] ;
please note that i need the last two values in vector c to be 8.0 and 5.5, which is less than 10.0
how can i do that? appreciate your help. thanks
Iain
Iain 2013년 6월 20일
Almost the same method:
i = find(a > 10,1);
b = a(1:i);
c = a((i+1):end);

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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by