Shifting columns while filling matrix with data
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kyra Oomen
el 1 de Dic. de 2023
Comentada: Dyuman Joshi
el 1 de Dic. de 2023
Hi,
I have created a database which is a 5x5 matrix of [1, 2, 3, 4, 5]. the first column consists of all ones, second of twos, etc. I am coding a moving object. At each position of the object, I am calculating 5 points that lay on a line perpendicular to the position of the object. I defined a matrix with these points the same size as my database with all zeros. I want to 'fill' the matrix by assigning a new value from my database in a loop. At the first location of the object the first column of my matrix filled with zeros, is now filled with the first column of my database. when the object has moved one timestep further, the second column of my zeros matrix should be filled with the first column of ones from my database and it's previous position should be updated to the second column of the database, etc. Instead it fills it the same way as my database. Can someone tell me how I can code this?
Thank you in advance!
0 comentarios
Respuesta aceptada
Dyuman Joshi
el 1 de Dic. de 2023
From what I understood -
n=5;
%database
x = meshgrid(1:n)
%matrix
y = zeros(n);
for k=1:n
y(:,1:k) = x(:,k:-1:1)
end
8 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Discrete Data Plots 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!
