how to iterate a matrix for multiple times
2 次查看(过去 30 天)
显示 更早的评论
Hi
I have a matrix, let's say, a random 5x5 matrix. In time period 1, it is a 5x5 random matrix, in time period 2, all element in the matrix are multiplied by 2 (a number), then in time period 3, all elements in time period 2 multiplied by 2 agian, so on and so forth until time period 30.
Actually this is a small part of my research, but i just begin working on Matlab so i am so confused with this step. Thank you so much for answering this question for me!
0 个评论
采纳的回答
James Tursa
2019-6-27
E.g., here is a possible outline
n = 30; % the number of iterations
M = rand(5,5); % some initial matrix
for k=1:n
M = 2*M; % or some other function involving M
end
If you need to save all the intermediate results, then something like this:
n = 30; % the number of iterations
M = zeros(5,5,n+1);
M(:,:,1) = rand(5,5); % some initial matrix
for k=2:n+1
M(:,:,k) = 2*M(:,:,k-1); % or some other function involving M(:,:,k-1)
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!