필터 지우기
필터 지우기

How do i write a line to display all the values that didn't meet the requirement

조회 수: 1 (최근 30일)
Limit = SigmaAp;
if any (SigmaAx > SigmaAp)
disp ('Some values above the limit.')
else
disp('All values are below the limit.')
end

채택된 답변

Chris
Chris 2021년 11월 9일
편집: Chris 2021년 11월 9일
SigmaAp = 5;
SigmaAx = randi(9,5,1)
SigmaAx = 5×1
8 6 2 2 6
idxs = find(SigmaAx>SigmaAp)
idxs = 3×1
1 2 5
disp('Values over the limit:');disp(SigmaAx(idxs))
Values over the limit: 8 6 6

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 11월 9일
Try this:
SigmaAp = 5.1;
SigmaAx = randi(9, 10, 1)
% Get a logical index of locations where SigmaAx > SigmaAp
aboveThresholdIndexes = find(SigmaAx > SigmaAp)
if ~isempty(aboveThresholdIndexes)
fprintf('These values are above the limit of %f:\n', SigmaAp)
% Print out what values are high, and their location:
for k = 1 : length(aboveThresholdIndexes)
fprintf('%f at index %d.\n', SigmaAx(aboveThresholdIndexes(k)), aboveThresholdIndexes(k));
end
else
fprintf('All values are below the limit of %f.\n', SigmaAp)
end
You'll see
SigmaAx =
7
3
5
7
9
9
5
2
2
3
aboveThresholdIndexes =
1
4
5
6
These values are above the limit of 5.100000:
7.000000 at index 1.
7.000000 at index 4.
9.000000 at index 5.
9.000000 at index 6.

카테고리

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