Implementing frame-by-frame 2D FFT data as an animation using plot inside a for loop
Show older comments
for iter=1:NumFrame % No. of Frame
figure(f1)
mesh(axis_r,axis_v,Data,"FaceColor","flat"); % 3D view plot
axis([-inf inf -2 2])
view(2)
axis('xy');
xlabel("Range (m)");
ylabel("Velocity (m/s)");
colormap('jet')
colorbar('v')
title_name=[int2str(iter),'Frame Range-Velocity Plot (dB)'];
title(title_name);
hold on;
drawnow;
hold off;
end
When using Matlab 2021, the code ran fine, plotting all frames through the for loop. However, after upgrading to Matlab 2023 and running the same code, only the last iteration of the for loop is plotted. Is it expected behavior for the code to not work due to the version upgrade?
4 Comments
Angelo Yeo
on 14 Feb 2024
Edited: Angelo Yeo
on 14 Feb 2024
Please share all the script for reproduction. Also specify exact release, e.g., R2021a or R2021b when you say MATLAB 2021.
Inseong
on 14 Feb 2024
Adam Danz
on 14 Feb 2024
> Is it expected behavior for the code to not work due to the version upgrade
No. Animations within a loop using drawnow are common and the recent release should not interrupt that workflow. I have some questions about the code in the question.
- This loop iterates over frames 1:NumFrame but I see nothing that changes between the iterations. The variable NumFrame isn't used and none of the other variables appear to update within the loop unless some of those arguments that appear to be variable names are functions. Therefore, all frames would look the same, except for, perhaps, a flicker due to destroying and recreating the figure on each iteration.
- The animation workflow is very inefficient. On each iteration, the axes content is replaced rather than updated. There's no reason to axx labels, assign colormaps, and set other axes properties such as view and limits on each iteration unless those properties change during the animation. You could also create one mesh objects outside of the loop and update its values instead of creating the mesh on each iteration. Here are some examples from the doc: https://www.mathworks.com/help/matlab/creating_plots/animate-graphics-object.html
Angelo Yeo
on 14 Feb 2024
Edited: Angelo Yeo
on 14 Feb 2024
@Inseong: If you want further investigation despite Adam's explanation, you can reach out to technical support with reproduction steps and scripts. I can find that your account has a valid license with SMS. Technical Support team can provide you a private&secure environment to share files. On top of general/theoretical explanation, the best way to investigate issue is to reproduce it.
Answers (0)
Categories
Find more on Graphics Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!