필터 지우기
필터 지우기

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에서 App Building에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by