Multiply specific elements that meet a certain condition?

11 visualizaciones (últimos 30 días)
Mateus Pianowski
Mateus Pianowski el 12 de Nov. de 2017
Movida: Sabin el 29 de En. de 2023
This is the problem: Generate a new vector called voltage_distorted and set it equal to vector voltage (I have the data for this). Now modify voltage_distorted such that all voltage values greater than 0 are multiplied by 2, and all values that are less than or equal to 0 are divided by 2.

Respuestas (1)

Osama Hussein
Osama Hussein el 12 de Nov. de 2017
Movida: Sabin el 29 de En. de 2023
for example:
voltage = [3 -6 -2 4 1];
voltage_distorted = voltage;
voltage_distorted(voltage_distorted>0) = voltage_distorted(voltage_distorted>0)*2;
voltage_distorted(voltage_distorted<=0) = voltage_distorted(voltage_distorted<=0)/2;
The answer will be:
voltage_distorted = [6 -3 -1 8 2]

Categorías

Más información sobre Sensors and Transducers en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by