How to compare every elements of a vector and update its element with a new one?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
mrbond99
el 22 de Jun. de 2020
Comentada: mrbond99
el 22 de Jun. de 2020
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 comentarios
Alan Stevens
el 22 de Jun. de 2020
Editada: Alan Stevens
el 22 de Jun. de 2020
Switch the order of the first two min_power statements, or use an if-else-end construct.
Respuesta aceptada
madhan ravi
el 22 de Jun. de 2020
Editada: madhan ravi
el 22 de Jun. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!