Multiply specific elements that meet a certain condition?

13 ビュー (過去 30 日間)
Mateus Pianowski
Mateus Pianowski 2017 年 11 月 12 日
移動済み: Sabin 2023 年 1 月 29 日
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.

回答 (1 件)

Osama Hussein
Osama Hussein 2017 年 11 月 12 日
移動済み: Sabin 2023 年 1 月 29 日
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]
  1 件のコメント
Mateus Pianowski
Mateus Pianowski 2017 年 11 月 12 日
移動済み: Sabin 2023 年 1 月 29 日
Thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSensors and Transducers についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by