Plotting in for loop by adding second dimension to the variables

조회 수: 2 (최근 30일)
Meva
Meva 2016년 5월 31일
댓글: Meva 2016년 5월 31일
Hello, I need to plot H,u at times
t=0.1, 0.2, 0.3, ...1
in the same plot over a range of time. I know below code is wrong but how can I fix it?
dt=0.01;
Nx = 101;
Nt= 101;
t=0;
H=zeros(1, Nx);
u=zeros(1, Nx);
for nt=1:Nt % time loop
t=(nt-1)*dt;
for i=1:Nx
H(i) = ...
u(i) = ...
end
for ntstep=1:10
t=(ntstep-1)*10*dt;
newH(ntstep,1:Nx)=H(1:Nx);
newu(ntstep,1:Nx)=u(1:Nx);
end
end
for i=1:10
hold on;
figure (1);
hplot1 = plot(x,newH(i,1:Nx),'lineWidth',1.3);
hold on
hplot1 = plot(x,newu(i,1:Nx),'lineWidth',1.3);
hold on
end
  댓글 수: 1
Meva
Meva 2016년 5월 31일
Hello,
I have changed the code as below:
dt=0.01;
Nx = 101;
Nt= 101;
t=0;
H=zeros(1, Nx);
u=zeros(1, Nx);
for nt=1:Nt % time loop
t=(nt-1)*dt;
for i=1:Nx
H(i) = ...
u(i) = ...
end
for k=1:10
if k*0.1 == nt
newH(k,1:Nx)=H(1:Nx);
newu(k,1:Nx)=u(1:Nx);
else
continue
end
end
end
for i=1:10
hold on;
figure (1);
hplot1 = plot(x,newH(i,1:Nx),'lineWidth',1.3);
hold on
hplot1 = plot(x,newu(i,1:Nx),'lineWidth',1.3);
hold on
end

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Fixed-Point Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by