Assigning an opertation vector to a variable

Hello there!
I am trying to assign this vector
v(mod(v,2)~=0)=0
The operations is supposed to replace odd numbers in a vector with 0. I am trying to assign this vector to result variable in a function.
This got an error:
v(mod(v,2)~=0)=0 = result;

Respuestas (1)

James Tursa
James Tursa el 15 de Mzo. de 2015
Is this what you want?
function result = myfunction(v)
v(mod(v,2)~=0) = 0;
result = v;
return

3 comentarios

But, how to make this work if we have 2 or more results?
function [result1,result2] = myfunction(v)
result1= v(v>10);
v(mod(v,2)~=0) = 0;
result2 = v;
return
Le Borge
Le Borge el 15 de Mzo. de 2015
Editada: James Tursa el 16 de Mzo. de 2015
or
function [result1,result2] = myfunction(v)
v(mod(v,2)==0)= 0;
result1 = v
v(mod(v,2)~=0) = 0;
result2 = v;
return
Is this what you want?
function [result1,result2] = myfunction(v)
result1 = v;
result1(mod(result1,2)==0)= 0;
result2 = v;
result2(mod(result2,2)~=0) = 0;
return
end

Iniciar sesión para comentar.

Categorías

Más información sobre Function Creation en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 15 de Mzo. de 2015

Comentada:

el 16 de Mzo. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by