Animation of plot upon changing parameter

51 ビュー (過去 30 日間)
Hexe
Hexe 2023 年 5 月 21 日
コメント済み: Hexe 2023 年 6 月 12 日
Hello! I have a code and a set of pictures at different values of parameter t. Is it possible to make an animation to see how the plot changes with changing time (t=0:3)? If somebody knows how, please, help me. Thank you.
s = 3;
n = 1;
t = 0.1;
r = 1;
a = 0:1:360;
a = a*pi/180;
b = sqrt(2*n*t);
L = sqrt((4*t+r^2)/3);
fun = @(k,u,c,a) ((k.^2).*exp(-1.5*k.^2)).*((u.^2).*(1-u.^2).*exp(-(b.*u).^2).*(cos(s.*k.*u.*cos(a)/L))).*(((cos(c)).^2).*(cos(s.*k.*sqrt(1-u.^2).*sin(a).*(cos(c)+sin(c))/(L*sqrt(2)))));
f3 = arrayfun(@(a)integral3(@(k,u,c)fun(k,u,c,a),0,Inf,-1,1,0,2*pi),a);
B = ((6*sqrt(6)*b^3)/(erf(b)*pi^2))*(1-(3/(2*b^2))*(1-((2*b*exp(-b^2))/(erf(b)*sqrt(pi))))).^(-1);
R = B*f3;
polar(a,R);

回答 (1 件)

Sugandhi
Sugandhi 2023 年 6 月 7 日
Hi Hexe,
I understand that you want to to make an animation to see how the plot changes with changing time.
Yes, it is possible to create an animation in MATLAB to see how a plot changes over time by looping through a sequence of plots and using the `pause` function to control the speed of the animation.
Here's an example of how to create an animation to display a plot of a function across time in MATLAB:
% Define function and time range
t = 0:0.1:3;
x = linspace(-2, 2);
y = zeros(length(x), length(t));
for k = 1:length(t)
y(:, k) = sin(x + t(k));
end
% Create animated plot
figure;
for k = 1:length(t)
plot(x, y(:, k));
xlabel('x');
ylabel('y');
title(sprintf('t = %0.1f', t(k)));
ylim([-1.5, 1.5]);
pause(0.1);
end
Use the `pause` function to pause the execution of the code for 0.1 seconds between each frame, creating the appearance of an animation.
Adjust the time range, and `pause` time as needed to create an animation that displays the changing plot of your function over time.
For more information, kindly go through the following links:
  1 件のコメント
Hexe
Hexe 2023 年 6 月 12 日
Thank you. I will try this.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by