why is there no output?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuestas (2)
Walter Roberson
el 5 de Mayo de 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.
0 comentarios
Azzi Abdelmalek
el 5 de Mayo de 2013
Maybe, you are not calling your function correctly
v=1:10
out=targil(v)
0 comentarios
Ver también
Categorías
Más información sobre Testing Frameworks en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!