Borrar filtros
Borrar filtros

Use the values in one matrix as index values to another matrix and replace with a value

2 visualizaciones (últimos 30 días)
Hello,
I have a matrix A of size 24 x 365 with certain values and I have a matrix B of zeros of the same size as A. I would like to replace the zeros in B with the value 5 in the position mentioned in A.
For example
I would like B to look like
I would appreciate any help thank you!

Respuestas (1)

David Hill
David Hill el 16 de Mzo. de 2022
The sizes of A and B in your example are not the same.
m=max(A,[],'all');
B=zeros(m,size(A,2));
a=A+(0:m:m*(size(A,2)-1));
B(a)=5;
  1 comentario
Ritika Srinivasan
Ritika Srinivasan el 16 de Mzo. de 2022
Thankyou for the answer that is just a snippet as i didnt want to show two 24x365 sized matrices. would the logic remain the same?

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing 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!

Translated by