Plot error: Index exceeds the number of array elements (104).

I am having the following error with plotting :
Index exceeds the number of array elements (104).
Error in MUSCL_main (line 144)
plot(Ini_x,history(h).U_Euler(1,:))
The code:
Nodes = 120;
cells = Nodes-1;
Ghost = 2;
Ini_x = Cells+2*Ghost;
U_Euler = zeros(8,Ini_x);
end_time = 6.0;
t= 0;
[dt_E] = DT(U_Euler, CFL, dx, 0);
n=0;
h=1;
while (t < end_time)
for k = 1:4
[U_Le, U_Re] = MUSCL(U_Le, U_Re , U_RK_Euler);
V_EulerL = switch_Con2Prim(U_Le, Gamma, mu_0, 0);
[Flux_E] = computeFluxes(Flux_E, V_EulerL, V_EulerR, U_Le,U_Re,dt_E,dx, 0);
[Res_E] = Residual(Flux_E, dx, dy, dz, Res_E);
[U_RKe] = RK4( U_Euler, dx, dy, dz, dt_E, k);
U_RK_Euler = Boundary_periodic(U_RKe);
end
U_Euler = U_RK_Euler;
t = t+dt_E;
if mod(n,10)== 0
history(h).U_Euler = U_Euler;
h=h+1;
end
n=n+1;
end
plot(Ini_x,history(h).U_Euler(1,:)) % error
I am trying to plot the data saved in the "history"

2 Kommentare

The error is clear, you are trying to extract more number of elements then present in the array. Check the dimensions of each array in the data used for plot.
So, you're saying I could use U_Euler isnead to plot not the history?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

KSSV
KSSV am 6 Mai 2021
Bearbeitet: KSSV am 6 Mai 2021
plot(Ini_x,history(end).U_Euler(1,:))

Weitere Antworten (0)

Tags

Gefragt:

am 6 Mai 2021

Bearbeitet:

am 6 Mai 2021

Community Treasure Hunt

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

Start Hunting!

Translated by