How to solve error for Index exceeds matrix dimensions

for k = 1:1:(length(n_taylor_range))
S = n_taylor_range(k);
ys_taylor(1:(length(t))) = 0;
xs_taylor(S,1:(length(t))) = 0.;
for w = 1:1:S
xs_taylor(w,:) = -((K(w)*pw*cos((2*pi*k(w)*t)/pw))/(2*k(w)*pi));
ys_taylor = xs_taylor(w,:)+ys_taylor;
end
yss_taylor(k,:) = ys_taylor;
P_taylor(k,:) = (fc*t)+(((bw*(t.^2))/(2*pw))+ (bw*yss_taylor(k,:)));
end

2 Comments

YOu have not given all the variable and did't specify the error line. And note that this error comes when you try to extract more number of elements then existing in the data.
Thanks Mr siva,
the all code like this :
%Parameter specifications of chirp signal%
fc = 0*1e6; %Frequency Carrier (MHz)%
bw = 10*1e6; %Bandwith (MHz)%
fs = 100*1e6; %Frequency sampling%
pw = 100*1e-6; %Pulsa Width (us)%
t = -(pw/2):(1/fs):(pw/2); %time%
th = 2*min(t):(1/fs):2*max(t); %time of convolution%
n = length(t); %Number of Sample%
nt = length(th); %Number of Sample Xcorr%
n_taylor_range = 1:1:30; %Taylor Range Coefficients
n_taylor = 3; %Choose The Taylor Coefficients
K = [-0.1142 0.0396 -0.0205 0.01253 -0.008409 0.005986 -0.004444 0.0034 -0.002658....
0.0021093 -0.00169902 0.001391 -0.00115689 0.00096693 -0.00080241 0.000664113....
-0.00056409 0.00049971 -0.00043663 0.00036352 -0.00030225 0.00025435 -0.00023125....
0.0002221 -0.00019499 0.00015746 -0.00011571 0.0001058 -0.000115179 0.000112324];
k = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30];
for k = 1:1:(length(n_taylor_range))
S = n_taylor_range(k);
ys_taylor(1:(length(t))) = 0;
xs_taylor(S,1:(length(t))) = 0.;
for w = 1:1:S
xs_taylor(w,:) = -((K(w)*pw*cos((2*pi*k(w)*t)/pw))/(2*k(w)*pi));
ys_taylor = xs_taylor(w,:)+ys_taylor;
end
yss_taylor(k,:) = ys_taylor;
P_taylor(k,:) = (fc*t)+(((bw*(t.^2))/(2*pw))+ (bw*yss_taylor(k,:)));
end
I think, the error in this code :
for w = 1:1:S
xs_taylor(w,:) = -((K(w)*pw*cos((2*pi*k(w)*t)/pw))/(2*k(w)*pi));
ys_taylor = xs_taylor(w,:)+ys_taylor;
end
perhaps you can help me,
thanks

Sign in to comment.

 Accepted Answer

You have written this between the code which is creating error.
k = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30];
for k = 1:1:(length(n_taylor_range))
S = n_taylor_range(k);
Loop index and the variable both are assigned by the same variable. So, try using different variable for the loop indices.
Now, your code runs successfully.
kk = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30];
for k = 1:1:(length(n_taylor_range))
S = n_taylor_range(k);
ys_taylor(1:(length(t))) = 0;
xs_taylor(S,1:(length(t))) = 0.;
for w = 1:1:S
w
xs_taylor(w,:) = -((K(w)*pw*cos((2*pi*kk(w)*t)/pw))/(2*kk(w)*pi));
ys_taylor = xs_taylor(w,:)+ys_taylor;
end
yss_taylor(k,:) = ys_taylor;
P_taylor(k,:) = (fc*t)+(((bw*(t.^2))/(2*pw))+ (bw*yss_taylor(k,:)));
end
for w = 1:1:S
xs_taylor(w,:) = -((K(w)*pw*cos((2*pi*kk(w)*t)/pw))/(2*kk(w)*pi));
ys_taylor = xs_taylor(w,:)+ys_taylor;
end

1 Comment

Thanks a lot Mr ANKUR KUMAR
you solved my problem

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics 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!