필터 지우기
필터 지우기

Condition

조회 수: 2 (최근 30일)
Manpreet Kapoor
Manpreet Kapoor 2011년 5월 11일
Hi,
I have a query.
Generally relational operators are used to check whether some condition is true. i.e. it returns a logical vector. Is it possible that the new vector has the same values as the original vector (based on some conditions). For eg, Suppose there is a vector with 10 elements [say (1,3,2,1,4,6,7,8,5,2)]and i put a condition that the new vector is formed such that it has elements which are only less say 5. How is that possible.?
Regards
  댓글 수: 1
Manpreet Kapoor
Manpreet Kapoor 2011년 5월 11일
I just need one more clarification. Can the size of the vector be decreased such that it neglects the values which are now 0.
i.e. suppose my vector length was earlier 10 and now the new vector has only 7 elements because rest of them are more than 5.

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 5월 11일
just
vnew = v.*(v<5)
  댓글 수: 1
Manpreet Kapoor
Manpreet Kapoor 2011년 5월 11일
I just need one more clarification. Can the size of the vector be decreased such that it neglects the values which are now 0.
i.e. suppose my vector length was earlier 10 and now the new vector has only 7 elements because rest of them are more than 5.

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

추가 답변 (1개)

Adrien Leygue
Adrien Leygue 2011년 5월 11일
Try this:
A = rand(1,10);
B = A(A<0.5);
C = zeros(size(A));
mask = A<0.5;
C(mask) = A(mask);
I think this could provide some answer.
A.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by