Multiple plotting issue?

2 vues (au cours des 30 derniers jours)
Andi
Andi le 27 Jan 2022
Commenté : Andi le 27 Jan 2022
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

Réponse acceptée

Ankit
Ankit le 27 Jan 2022
Modifié(e) : Ankit le 27 Jan 2022
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 commentaires
Ankit
Ankit le 27 Jan 2022
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 le 27 Jan 2022
Exactly, I want to build a video of all these plot. Thanks for sharing

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur App Building dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by