Attempted to access x(1,53); index out of bounds because size(x)=[1,2].
6 views (last 30 days)
Show older comments
Why do i get this error?
i
clear
clc
n=zeros(52,60001);
N=51;
d=0.4;
A=0.15;
B=1.6;
fo=0.05;
e=2*pi*rand(1,51); %epsilon
j=1;
for i=1:N;
f(i)=(1.1^i)*fo;
T(i)=1/f(i);
k(i)=2*pi/dispersion(T(i),d);
eta(i)=0.5*(1+(2*k(i)*d/sinh(2*k(i)*d)));
ph(i)=(1/2*n(i))*tanh(k(i)*d)^2;
a(i)=(0.2*f(i)*(0.205*A^2*B^-4*f(i)^-5*exp(-0.75*(B*f(i)^-4))*ph(i)))^0.5;
end
for t=0:0.005:300
x(j,1)=t;
for i=1:50;
x(j,i+1)=a(i)*cos(2*pi*f(i)*t+e(i));
x(j,N+2)=x(j,N+2)+x(j,i+1);
end
j=j+1;
end
plot(x(:,1),x(:,N+2))
0 Comments
Answers (1)
James Tursa
on 31 Oct 2018
Type the following at the MATLAB command prompt:
dbstop if error
Then run your code. When the error occurs, the program will pause with all current variables intact. Examine them to see what the sizes are, then backtrack through your code to figure out why the sizes are not what you expect.
0 Comments
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!