Borrar filtros
Borrar filtros

A(B)=0 What is its meaning?

9 visualizaciones (últimos 30 días)
zhenyu zeng
zhenyu zeng el 6 de Mzo. de 2019
Editada: Torsten el 6 de Mzo. de 2019
A=rand(5)
B=A>0.8
A(B)=0
Can you tell me what is A(B)=0 meaning?

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 6 de Mzo. de 2019
B is a logical index matrix. You can see the value is 1 (true) or 0 (false) wherever the corresponding value in A is greater than 0.8.
A(B)=0 means for all those places where B's value is true, set the corresponding value in A to 0.
Use this example to see it better.
A=magic(5)
B=A>10
A(B)=0
  3 comentarios
Torsten
Torsten el 6 de Mzo. de 2019
Editada: Torsten el 6 de Mzo. de 2019
It's the same as if you ask why MATLAB loops if you write
for i=1:n
...
end
It's just MATLAB syntax.
Look up "Logical indexing":
https://blogs.mathworks.com/loren/2013/02/20/logical-indexing-multiple-conditions/
Fangjun Jiang
Fangjun Jiang el 6 de Mzo. de 2019
It is a very efficient way for programming.

Iniciar sesión para comentar.

Más respuestas (1)

Torsten
Torsten el 6 de Mzo. de 2019
Editada: Torsten el 6 de Mzo. de 2019
All numbers in the matrix A that are bigger than 0.8 are set to 0.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by