How do I use numerical and logical indices to get this output?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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]
0 comentarios
Respuestas (1)
per isakson
el 25 de Feb. de 2021
Editada: per isakson
el 25 de Feb. de 2021
One out of many ways
%%
myArray = [2, 4, -3, 6, 9];
isneg = myArray < 0;
myArray( isneg ) = 1;
Ver también
Categorías
Más información sobre Multidimensional Arrays 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!