How to use imagesc in a time loop?

5 views (last 30 days)
Hi,
I am using imagesc to visualize a binary matrix (of zeroes and ones), which, at every time step, changes (more ones apperars).
I want the figure to hold on each time step so that I can visulize the change in the matrix. How can i do that with out 100 figures popping up?
This is the code for the figure:
for time = 1:timeSteps
newMatrix = GenerateNewMatrix(matrix,probability);
matrix = newMatrix;
figure; hAxes = gca;
imagesc(hAxes, matrix);
colormap(hAxes , [1 1 1; 1 0 0; 0 1 0] );
end

Accepted Answer

KSSV
KSSV on 15 Nov 2019
for time = 1:timeSteps
newMatrix = GenerateNewMatrix(matrix,probability);
matrix = newMatrix;
hAxes = gca;
imagesc(hAxes, matrix);
colormap(hAxes , [1 1 1; 1 0 0; 0 1 0] );
end
Remove the figure line in the loop.
  1 Comment
Tilia Selldén
Tilia Selldén on 15 Nov 2019
I have tried that but that only generates the last figure and not the time siries

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Properties 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!