Condition which reduces the size of the vector
조회 수: 1 (최근 30일)
이전 댓글 표시
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), but it must change the size of the vector neglecting the values which do not satisfy the condition. 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 than a value(say 5). Thus the new vector must have only 6 elements(neglecting the terms higher than 5) How is that possible?
댓글 수: 0
채택된 답변
Matt Fig
2011년 5월 11일
v = [1,3,2,1,4,6,7,8,5,2];
vnew = v(v<5) % Returns: vnew = [1 3 2 1 4 2]
댓글 수: 0
추가 답변 (1개)
Andy
2011년 5월 11일
I don't quite understand your question. If
A = [1,3,2,1,4,6,7,8,5,2];
then you say the new vector should have six elements. But this input vector has seven elements not higher than 5. I will assume this was just a typo. I think you want the following:
B = A(A<6);
This should return B = [1,3,2,1,4,5,2].
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Gamma Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!