필터 지우기
필터 지우기

find result from multiple if and range value

조회 수: 2 (최근 30일)
badrul hisham
badrul hisham 2016년 4월 10일
편집: Andrei Bobrov 2016년 4월 10일
hello, can someone help me? i have a set of range and i need the number produced from the the range. example: if i input a value of 0.17,it will find 0.17 is in which range (in this case it is in between 0.138 to 0.205) and then it will display the number of that range category which is 6.0
0.0 To 0.068 = 7.0
0.069 To 0.137 = 6.5
0.138 To 0.205 = 6.0
0.206 To 0.274 = 5.5
0.275 To 0.342 = 5.0 .
0.343 To 0.410 = 4.5
0.411 To 0.479 = 4.0
0.480 To 0.547 = 3.5
0.548 To 0.615 = 3.0
0.616 To 0.684 = 2.5
0.685 To 0.752 = 2.0
0.753 To 0.821 = 1.5
0.822 To 0.890 = 1.0

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 10일
편집: Azzi Abdelmalek 2016년 4월 10일
Edit2
r=[0.0 .068 7.0
0.069 0.137 6.5
0.138 0.205 6.0]
a=0.032
b=mat2cell(r(:,1:2),ones(size(r,1),1),2)
idx=cellfun(@(x) x(1)<=a & x(2)>=a,b)
sprintf('the range of a is %0.1f',r(idx,3))
  댓글 수: 5
Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 10일
Look again at edited answer. I think this is the good one
badrul hisham
badrul hisham 2016년 4월 10일
thank you so much for your help sir. this works perfectly now

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

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2016년 4월 10일
편집: Andrei Bobrov 2016년 4월 10일
x =[ 0 7.0000
0.0690 6.5000
0.1380 6.0000
0.2060 5.5000
0.2750 5.0000
0.3430 4.5000
0.4110 4.0000
0.4800 3.5000
0.5480 3.0000
0.6160 2.5000
0.6850 2.0000
0.7530 1.5000
0.8220 1.0000];
t = 0.890;
a = rand(30,1)*t;
[~,~,bin] = histcounts(a,[x(:,1);t]);
out = x(bin,2);

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by