Borrar filtros
Borrar filtros

Replacing values in a matrix based on values in another matrix

13 visualizaciones (últimos 30 días)
If I have a matrix with "1"s and "0"s (A) and other matrixes of the same size with other values (B,C,D, etc), is it possible to find the locations of the "1"s in A in B,C,D,etc and replace these values with a constant number while the other values in B,C,D, etc are uneffected?
Thanks in advanced!

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 15 de Ag. de 2022
Use logical indexing (see Ch 11 of MATLAB Onramp)
A = [0 1 1 0]
A = 1×4
0 1 1 0
B = rand(size(A))
B = 1×4
0.1915 0.9248 0.8352 0.2674
B(A==1) = 99
B = 1×4
0.1915 99.0000 99.0000 0.2674

Más respuestas (0)

Categorías

Más información sobre Operating on Diagonal Matrices 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!

Translated by