How do I use numerical and logical indices to get this output?

2 vues (au cours des 30 derniers jours)
Luming Tan
Luming Tan le 24 Fév 2021
Commenté : Luming Tan le 25 Fév 2021
Provide Matlab code that generates the following output. Given the vectors:
myArray = [2, 4, -3, 6, 9]
How do I use numerical indices and logical indices to get this:
myArray = [2, 4, 1, 6, 9]

Réponses (1)

per isakson
per isakson le 25 Fév 2021
Modifié(e) : per isakson le 25 Fév 2021
One out of many ways
%%
myArray = [2, 4, -3, 6, 9];
isneg = myArray < 0;
myArray( isneg ) = 1;
  1 commentaire
Luming Tan
Luming Tan le 25 Fév 2021
Appreciate!! that's exactly what I am looking for!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Multidimensional Arrays 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