Borrar filtros
Borrar filtros

Assign values to intervals of matrix

2 visualizaciones (últimos 30 días)
d7366431
d7366431 el 14 de Mayo de 2020
Comentada: d7366431 el 14 de Mayo de 2020
Hi,
Could you please tell me how to assign values to each of 580 elements in the matrix.
Let say I have nx3 matrix and for the first 580 elements of 3rd column should be assigned value from the 1st element of the vecor t1 (mx1 size), for the next 580 elements of 3rd column should be assigned 2nd element of the vector t1.
I tried to implement it with the for loop, but the problem is how to iterate through the t1(z).
Thank you!
for i=1:580:length(A)
for k=1:580
A(i+k-1:i+k-1,3)=t1(z);
end
end

Respuesta aceptada

John D'Errico
John D'Errico el 14 de Mayo de 2020
Editada: John D'Errico el 14 de Mayo de 2020
Use MATLAB as it is designed to be used - as a language that works with vectors and matrices.
A(:,3) = repelem(t1,580);
  1 comentario
d7366431
d7366431 el 14 de Mayo de 2020
Thank you! Just Genius! I didn't know about this function =)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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