How do I define and use a standard range written by variable

조회 수: 1 (최근 30일)
edo nissim
edo nissim 2020년 2월 4일
댓글: Walter Roberson 2020년 2월 4일
Hi every one!
I want to define the standard range "690N to 1200N" (N has to be a positive and integer number).
hen when i get a number I want to check if the number that I got is in my range (690-1200 or 1380-2400 or 2070-3600 or...).
Thank you very much!
Robert

답변 (2개)

Ruger28
Ruger28 2020년 2월 4일
N = 1;
RangedValues = [690*N:1200*9]; % set your range, assuming your values are always 690 and 1200 * N
Num2Check = 1459; % number to see if it is within range
if Num2Check >= RangedValues(1) && Num2Check <= RangedValues(end) % check greater than first value and less than last
disp('Number is within range');
% rest of code below since nnumber is within range
end
  댓글 수: 2
edo nissim
edo nissim 2020년 2월 4일
Thank you but I know how to check if the N is known (like you did with N=1).
I would like to know when I dont know what is N and it is can be any number/ I want the the software to with the options of N automatically. thanks.
Walter Roberson
Walter Roberson 2020년 2월 4일
if ~exist('N', 'var') || isempty(N)
you do not know what N is
else
N exists and is non-empty but you need to check that it is valid
end
See also https://www.mathworks.com/help/matlab/ref/double.discretize.html

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


Fangjun Jiang
Fangjun Jiang 2020년 2월 4일
편집: Fangjun Jiang 2020년 2월 4일
N=10; % provide a reasonable number based on the range of input data
n=1:N;
LowBound=690*n;
HighBound=1200*n;
InputData=[100 1000 1300 1400]' ;
OutputFlag=any(and(InputData>LowBound, InputData<HighBound),2)

카테고리

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