Multiple plotting issue?

2 次查看(过去 30 天)
Andi
Andi 2022-1-27
评论: Andi 2022-1-27
Hi everyone,
As per my script i expect an oputput of three plots but I get only one plot.
May someone suggets how i can fix this.
As per code there shoudl be three plots for t=1, 2 and 3, but i get only one plot for t=3.
clear all
clc
xs=8;
v=3;
L=20;
ta=0.2;
t=1:1:3;
for k=1:length(t)
n=1:1:40;
x=0:0.1:20;
omga = zeros(1,length(n));
F = zeros(1,length(n));
u = zeros(length(n),length(x));
for j=1:length(n)
F(j)=exp(-((n(j)*pi*v*ta/L).^2)/4);
u(j,:)=sin(n(j)*pi*xs/L)*F(j)*sin(n(j)*pi*x/L)*cos(n(j)*pi*v/L*t(k)); % no loop needed
end
us = sum(u);
plot(x,us)
end

采纳的回答

Ankit
Ankit 2022-1-27
编辑:Ankit 2022-1-27
Few recommendations to your code:
  • try to define all the variable before loop
  • don't use clear all in your code. Calling clear all decreases code performance, and is usually unnecessary. To clear one or more specific variables from the current workspace use clearvars instead
clc
xs=8;
v=3;
L=20;
ta=0.2;
t=1:1:3;
n=1:1:40;
x=0:0.1:20;
us = zeros(1,length(x));
omga = zeros(1,length(n));
F = zeros(1,length(n));
u = zeros(length(n),length(x));
for k=1:length(t)
for j=1:length(n)
F(j)=exp(-((n(j)*pi*v*ta/L).^2)/4);
u(j,:)=sin(n(j)*pi*xs/L)*F(j)*sin(n(j)*pi*x/L)*cos(n(j)*pi*v/L*t(k)); % no loop needed
end
us(k,:) = sum(u);
end
plot(x,us);
  3 个评论
Ankit
Ankit 2022-1-27
what do you mean by video of these plots? you mean how one by one all your three plots are plotted?
here you can see some options: Get figures and use them to build a video.avi - (mathworks.com). You can also search on MATLAB File Exchange
Andi
Andi 2022-1-27
Exactly, I want to build a video of all these plot. Thanks for sharing

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by