How do i extract values from an array for different binary string generated?

1 vue (au cours des 30 derniers jours)
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
TANUMOY KOLAY
TANUMOY KOLAY le 21 Mai 2018
Eg. A=[15 16 18 20 17 19]; these are the cost values for 6 plants. I run a for loop to generate 5 binary strings where 1 means plant is open and 0 means plant is closed. Suppose for i=1 string generated is 100110. So the code should print corresponding cost values for plants 1, 4, 5. again a new binary string is generated suppose 111001 and again the fixed cost must be printed for corresponding open plants. this needs to be done 5 times.

Connectez-vous pour commenter.

Réponse acceptée

Ameer Hamza
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.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by