필터 지우기
필터 지우기

Extracting the first three minimum elements from a vector v and assign them to h then letter remove the elements from vector v and used the index to removed some element in vector w.

조회 수: 5 (최근 30일)
v=[3,6,1,7,9,4];
w=[3,2,7,1,9,5];
[x,y]=sort(v);
h=x(1:3);
i=1;
while i<=numel(v)
if v(i)==h(i) % here h will be less than the elements in v, so it give me error
v(i)=[];
else
v(i)=v(i);
end
i=i+1;
trying to take the first three minimum elements in vector v and assigned the values to h, and after then, remove those elements from v, and use index of the removed elements of v, to remove some elements in w.
e.g v=
  댓글 수: 6

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

채택된 답변

Bashir Yusuf Bichi
Bashir Yusuf Bichi 2017년 12월 6일
편집: Bashir Yusuf Bichi 2017년 12월 6일
v(h)=[];
w(h)=[];
thanks @KSSV, I got it. I don't have to use the while loop.

추가 답변 (1개)

KSSV
KSSV 2017년 12월 6일
v=[3,6,1,7,9,4];
[k,idx] = sort(v) ;
h = k(1:3) ;
%%Remove from k
k(1:3) = []
%%Remove from v
v(idx(1:3))=[]

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by