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;

답변 (1개)

James Tursa
James Tursa 2015년 3월 15일

0 개 추천

Is this what you want?
function result = myfunction(v)
v(mod(v,2)~=0) = 0;
result = v;
return

댓글 수: 3

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 2015년 3월 15일
편집: James Tursa 2015년 3월 16일
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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Function Creation에 대해 자세히 알아보기

제품

질문:

2015년 3월 15일

댓글:

2015년 3월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by