How to exclude a certain value from a range?

조회 수: 22 (최근 30일)
Arnab Mondal
Arnab Mondal 2024년 8월 17일
댓글: Walter Roberson 2024년 8월 18일
Suppose a variable has upper limit and lower limit of 1 and 54 [1 54] and I and to exclude one value say 30 from it. How to it?
For example:
a = [0 576;0 100; 0 140;0 100;0 550;0 100;0 410];
b = [0.95 1.1;0.95 1.1;0.95 1.1;0.95 1.1;0.95 1.1;0.95 1.1;0.95 1.1];
c = [0.9 1.1;0.9 1.1;0.9 1.1;0.9 1.1;0.9 1.1;0.9 1.1;0.9 1.1;0.9 1.1;0.9 1.1;0.9 1.1;0.9 1.1;0.9 1.1;0.9 1.1;0.9 1.1;0.9 1.1;0.9 1.1;0.9 1.1];
d = [0 20;0 20;0 20];
e = [2 7; 2 7; 2 7];
limit = [a;b;c;d;e]';
In this case from e, I want to exclude the value 6.

답변 (2개)

Image Analyst
Image Analyst 2024년 8월 17일
It doesn't look like your "e" has a value of 6, but if it did, you'd do this
e = e(e ~= 6); % e must be a vector.
If e is a matrix, then you can't remove isolated elements since a matrix must remain rectangular. You can however set the location of 6's to nan:
e(e == 6) = nan; % e is a matrix
To learn other fundamental concepts, invest 2 hours of your time here:

Walter Roberson
Walter Roberson 2024년 8월 17일
e = 1:9
e = 1x9
1 2 3 4 5 6 7 8 9
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
e = standardizeMissing(e, 6)
e = 1x9
1 2 3 4 5 NaN 7 8 9
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  댓글 수: 2
Image Analyst
Image Analyst 2024년 8월 18일
Cool - I didn't know about that function. Kind of a weird name for it though.
Walter Roberson
Walter Roberson 2024년 8월 18일
The name kind of makes sense when you understand that the purpose of the function is to take data that has non-standard "missing" data markers, and to standardize the missing data to NaN

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by