How do i extract values from an array for different binary string generated?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
TANUMOY KOLAY
le 21 Mai 2018
Commenté : Ameer Hamza
le 22 Mai 2018
Suppose i have an array for fixed cost of plants A=[15 16 18 20 17 19]; I run a loop and generate 5 binary strings. In 1st string plants suppose 2, 3, 4 are open. How to extract corresponding fixed cost values for these open plants? In 2nd string suppose plants 1, 6, 7 are open and i need to print the corresponding fixed costs again. This process is to be repeated 5 times. The string generation is done randomly.
2 commentaires
Réponse acceptée
Ameer Hamza
le 21 Mai 2018
Modifié(e) : Ameer Hamza
le 21 Mai 2018
Try this
A=[15 16 18 20 17 19];
str = '010101'; % specify your string
activePlants = A(find(str - '0')) % it will store the active plants
activePlants =
16 20 19
You can run it in a for loop with your strings with the last line.
2 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!