Shifting columns while filling matrix with data
17 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Dyuman Joshi
on 1 Dec 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 Comments
More Answers (0)
See Also
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!