Shifting columns while filling matrix with data
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Dyuman Joshi
le 1 Déc 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Discrete Data Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
