Replace value with index in 2D array
27 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tha saliem
el 3 de Abr. de 2017
Comentada: Star Strider
el 3 de Abr. de 2017
Hi I have a 2D array like this
A=[0 0 1; 1 0 1; 0 1 0]
I want to replace 1 in each row with column index value. e.g new matrix will be like this:
result=[0 0 3 ; 1 0 3 ; 0 2 0]
Thanks in advance
0 comentarios
Respuesta aceptada
Star Strider
el 3 de Abr. de 2017
This works:
A=[0 0 1; 1 0 1; 0 1 0];
[~,CIV] = find(A); % ‘CIV’ = ‘Column Index Value’
A(A>0) = CIV
result = A
result =
0 0 3
1 0 3
0 2 0
5 comentarios
Más respuestas (2)
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!