How to compare every elements of a vector and update its element with a new one?
1 view (last 30 days)
Show older comments
wo = [0.200,0.367,0.100,0.100,1.667];
k = 1:size(wo,2);
min_power(wo(k) >= 0.90) = 1e-4;
min_power(wo(k) >= 0.70) = 1e-5;
min_power(wo(k) < 0.70) = 1e-7;
The last element of wo(1.667) is not updated with 1e-4 but instead to 1e-5. Where is my mistake?
2 Comments
Alan Stevens
on 22 Jun 2020
Edited: Alan Stevens
on 22 Jun 2020
Switch the order of the first two min_power statements, or use an if-else-end construct.
Accepted Answer
madhan ravi
on 22 Jun 2020
Edited: madhan ravi
on 22 Jun 2020
min_power = (wo >= 0.90) * 1e-4 ...
+ ((wo >= 0.70) & (wo < 0.90)) * 1e-5 ...
+ (wo < 0.70) * 1e-7
*Note:* 1.667 satisfies two conditions first it satisfies >= .9 and later with .7 so MATLAB assigns 1e-5 with latter condition.
You need to decide which condition you want it to satisfy for.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!