필터 지우기
필터 지우기

why is there no output?

조회 수: 2 (최근 30일)
Lee
Lee 2013년 5월 5일
im suppose to create a function that gets a vector x of 10 elements and returns
a new vector with 10 elemnts.the new vector component (i) is e if i was bigger then 1 1/e if i was smaller then zero and e^(2*x(1,i)-1) if i was between 0 and 1
this is what i did for some reason i get no return what am i doing wrong?
function targil7=targil(x)
z=length(x);
w=zeros(1,10);
for i=1:z
if x(1,i)>1
w(1,i)=w(1,i)+exp(1);
else if x(1,i)<0
w(1,i)=w(1,i)+exp(-1);
else if 0<x(1,i)<1
w(1,i)=w(1,i)+exp(2*(x(1,i)-1));
end
end
end
end
targil7=w;
whats am i doing wrong?

답변 (2개)

Walter Roberson
Walter Roberson 2013년 5월 5일
if 0<x(1,i)<1
is not correct. To MATLAB it means ((0<x(1,i)) < 1) which means to compute the logical result of the comparison to 0, getting a 0 or 1 as a result, and then to test that value to see if it is less than 1. Try
if 0 < x(1,i) & x(1,i) < 1
Note: when you do that, you need to figure out what you want to do if that test is not true either. If there are no circumstances under which it could be false at that point, then skip the test and just do the assignment.

Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 5일
Maybe, you are not calling your function correctly
v=1:10
out=targil(v)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by