column multiplication by specific number with some condition

3 visualizaciones (últimos 30 días)
Nazar Tarlanli
Nazar Tarlanli el 14 de Nov. de 2018
Comentada: madhan ravi el 15 de Nov. de 2018
r = -5 + (5+5)*rand(10,1) % column with positive and negative numbers
I want to create the function r_1 by satisfying the following:
r_1= r .* 0.5 if r >0
and
r_1 = r .* 0.7 if r<0
I guess, I should multiply positive values by 0.5 and negative values by 0.7.

Respuestas (1)

madhan ravi
madhan ravi el 15 de Nov. de 2018
Editada: madhan ravi el 15 de Nov. de 2018
r_1=ones(1,numel(r)):
r_1(r>0)=r(r>0).*.5;
r_1(r<0)=r(r<0).*.7;
r_1
  2 comentarios
Nazar Tarlanli
Nazar Tarlanli el 15 de Nov. de 2018
Editada: Nazar Tarlanli el 15 de Nov. de 2018
r_1=zeros(size(r));
r_1(r>0)=r(r>0).*.5;
r_1(r<0)=r(r<0).*.7;
r_1
I did run this code,it work. Thanks
madhan ravi
madhan ravi el 15 de Nov. de 2018
Anytime :) make sure to accept the answer if it worked

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by