I tried to solve problem but I couldn'!

조회 수: 2 (최근 30일)
zehra ülgen
zehra ülgen 2020년 10월 18일
댓글: zehra ülgen 2020년 10월 19일
Write a function called between that takes one scalar and two vectors of the same length as input arguments (the function does not have to check the format of the input) and returns one scalar output argument. If it is called like this, n = between(a,u,v), then n is equal to the number of indices ii for which the scalar a is between u(ii) and v(ii) or a is equal to u(ii) or v(ii). Here are some examples for the case in which the length of the vectors is 4:
  댓글 수: 1
zehra ülgen
zehra ülgen 2020년 10월 18일
>> n = between(4,[5,0 -7 6], [3, 9, 4, 4])
n =
4
>> n = between(5,[5,0 -7 6], [3, 9, 4, 4])
n =
3
>> n = between(6,[5,0 -7 6], [3, 9, 4, 4])
n =
2
>> n = between(9,[5,0 -7 6], [3, 9, 4, 4])
n =
1
>> n = between(10,[5,0 -7 6], [3, 9, 4, 4])
n =
0

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

채택된 답변

Payam Morsali
Payam Morsali 2020년 10월 18일
function y=compare(n,A,B)
y=0;
for i=1:length(A)
if n>=A(i) && n<=B(i)
y=y+1;
elseif n>=B(i) && n<=A(i)
y=y+1;
end
end
end
  댓글 수: 3
John D'Errico
John D'Errico 2020년 10월 19일
Please don't do assignments for people when they show no effort to do it themselves. This teaches them nothing, except how to get someone else to do their work for them.
zehra ülgen
zehra ülgen 2020년 10월 19일
I tried to solve problem.. That's my answer in a different way..
function n = betweenn(a, u, v)
n = sum((u <= a & a <= v) | (v <= a & a <= u));
end

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by