How to solve error for Index exceeds matrix dimensions
2 views (last 30 days)
Show older comments
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
KSSV
on 6 Dec 2017
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.
Accepted Answer
ANKUR KUMAR
on 6 Dec 2017
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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!