Why do i receive "Error using plot. Data cannot have more than 2 dimensions"

9 visualizaciones (últimos 30 días)
I had been trying to plot the equations for S,I and R but i am receiving this "Error using plot.Data cannot have more than 2 dimensions"
Here is the code:
t=18;
N=100;
S0=0.8;
I0=0.2;
R0=0;
beta = 100/365;
mu = 0.014/365;
gamma = 0.2/365;
sigma = 50/365;
m = 0.0001/365;
a=0.5;
b=0.9;
NA = 3;
NL = 7;
NS = NA^NL;
C = 2*NL*NS;
d=7;
S=zeros(1,C);
I=zeros(1,C);
R=zeros(1,C);
K=zeros(1,C);
s=zeros(1,C);
S(1)=S0;
I(1)=I0;
R(1)=R0;
lambda=0.1;
y=0.01;
y1=0.25;
lambda1=0.76;
for t1=1:1:18
K(t1+1)=t1;
kmax=NS;
imax=NL-1;
S=zeros(imax,kmax,t1);
R=zeros(imax,kmax,t1);
for k=1:1:kmax
for i=1:1:imax
S(i,k,t1+1)=S(i,k,t1)+mu*(1-S(i,k))-S(i,k)*lambda+gamma*R(i,k);
I(i,t1+1)=I(t1)+beta*I(i)*y-sigma*I(i)+N*m*y1;
R(i,k,t1+1)=R(i,k,t1)+S(i,k)*lambda1-(gamma+mu)*R(i,k);
end
end
end
plot(K,S,'r.-');
hold on
plot(K,I,'b-o')
hold on
plot(K,R,'k-d')
hold off

Respuestas (1)

Walter Roberson
Walter Roberson el 22 de Jun. de 2021
You have variables with three indices. plot() is a tool for 2d line plots,and cannot handle 3d arrays.
When you have 3d arrays, your options include:
  • slice()
  • isosurface()
  • volumeViewer()
  • animations
You are trying to plot a cuboid of data, which is a problem even in 3d, as outer parts of the data hide inner parts.

Community Treasure Hunt

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

Start Hunting!

Translated by