필터 지우기
필터 지우기

How do I remove element lower/greater than a certain value in a matrix?

조회 수: 137 (최근 30일)
Lets say I have
A = 1
3
2
7
4
10
12
9
8
15
13
So in this case, i want to remove values lower than 5 and greater than 11 , so i will end up getting this:
A = 7
10
9
8
How should I do this?

채택된 답변

Image Analyst
Image Analyst 2014년 11월 5일
Try this:
A = [1
3
2
7
4
10
12
9
8
15
13]
rowsToDelete = A < 5 | A > 11
A(rowsToDelete) = []
Give you exactly what you asked for.

추가 답변 (1개)

dpb
dpb 2014년 11월 5일
Use my helper function iswithin
>> A(iswithin(A,5,11))
ans =
7
10
9
8
>> >> type iswithin
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by