Multiple plotting issue?

7 visualizaciones (últimos 30 días)
Andi
Andi el 27 de En. de 2022
Comentada: Andi el 27 de En. de 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

Respuesta aceptada

Ankit
Ankit el 27 de En. de 2022
Editada: Ankit el 27 de En. de 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 comentarios
Ankit
Ankit el 27 de En. de 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 el 27 de En. de 2022
Exactly, I want to build a video of all these plot. Thanks for sharing

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre App Building en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by