Effacer les filtres
Effacer les filtres

why is there no output?

3 vues (au cours des 30 derniers jours)
Lee
Lee le 5 Mai 2013
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?

Réponses (2)

Walter Roberson
Walter Roberson le 5 Mai 2013
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 le 5 Mai 2013
Maybe, you are not calling your function correctly
v=1:10
out=targil(v)

Catégories

En savoir plus sur Testing Frameworks dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by