i want to code the following such that the negative values get saved in zerocoeff and then the negative values becomes zero . I have tried something but i m still getting an empty zerocoeff .
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
kitty varghese
el 29 de Ag. de 2017
for i5=1:vdim*rdim
v(i5)=w(i5)+alpha(i5)*w(i5);
if v(i5)<0
zerocoeff = v(i5<0);
v(i5)=0;
else
v(i5)=v(i5);
end
end
0 comentarios
Respuesta aceptada
Jan
el 29 de Ag. de 2017
Editada: Jan
el 29 de Ag. de 2017
What is the intention of "v(i5)=v(i5)"?
Do you need a loop?
v = w + alpha .* w;
lt0 = (v < 0);
zerocoeff = v(lt0);
v(lt0) = 0;
Please use the debugger to examine what happens in your code. Set a breakpoint and step through the program line by line. Then you will see problems like "v(i5<0)", where the value of the index is checked, and not the value of the vector v.
Note that zerocoeff = v(i5<0) overwrites zerocoeff in each iteration.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Function Creation 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!