How index using inequalities
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Danny Maefengea
el 21 de Jun. de 2020
Comentada: Danny Maefengea
el 22 de Jun. de 2020
Hello guys, I was doing this exercise and when I tried running my script, errors appeared.
Create a 1*100 vector A with random numbers from 0 to 10
A = randi([0,10],1,100)
Display all the numbers in A that are greater than 5
u = disp(A>5)
Delete all the numbers in A that are greater than 5
u = []
0 comentarios
Respuesta aceptada
Walter Roberson
el 22 de Jun. de 2020
A>5 creates a logical vector, with each entry being true if the corresponding A was (strictly) greater than 5, and false if the corresponding A was less than or equal to 5.
disp(A>5) would display that logical vector.
To display the contents of A where A > 5 you need to use A>5 to select entries out of A using logical indexing.
SomeArray(logical_mask)
However... disp() does not return any value, and it is an error to attempt to assign disp() to a variable.
u = []
If you had assigned u the parts of A that are greater than 5, then u = [] would just empty out that array, without changing A. You again want to use logical indexing
SomeArray(logical_mask) = []
3 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Identification en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!