How can I fix the error: Index exceeds the number of array elements (1)?
1 view (last 30 days)
Show older comments
I am trying to plot a gragh of the eqution below when there is a relation between N_k, t, t_j. The relation is that N_k is the integer of t/tt.(when I define t_j=tt*N_k)
I'm confused how I can get the each value when t is changing within the range and apply the effects on the other components. I tried use array and matrix with 'for', but I getting an error 'Index exceeds the number of array elements (1)'. How can I fix it? Also, is this a right solution to solve this equation? Any comment will be helpful, thank you.
code:
clear
B_n = -5.36;
omega_d = 400;
zeta = 29;
tt=0.01;
upTo_t=10;
total = zeros(upTo_t*100, 1);
for i=1:upTo_t*100
t=0.01*i;
T=t/tt;
N_k=floor(T);
points = zeros(1, N_k);
for j=1:N_k
t_j= tt*j;
points(i,j) = exp(-(zeta/2).*(t(i)-t_j(j))).*(-zeta*(sin(omega_d/2.*(t(i)-t_j(j))))+ omega_d.*cos(omega_d/2*(t(i)-t_j(j))));
end
total(i,1) = B_n/omega_d.*sum(points(i,j));
end
plot(t, total)
0 Comments
Accepted Answer
Voss
on 16 Mar 2023
clear
B_n = -5.36;
omega_d = 400;
zeta = 29;
tt=0.01;
upTo_t=10;
N = upTo_t*100;
total = zeros(N, 1);
t=0.01*(1:N);
for i=1:N
t_j= tt*(1:i);
points = exp(-(zeta/2).*(t(i)-t_j)) ...
.*(-zeta*(sin(omega_d/2.*(t(i)-t_j)))+ omega_d.*cos(omega_d/2*(t(i)-t_j)));
total(i,1) = B_n/omega_d.*sum(points);
end
plot(t, total)
More Answers (0)
See Also
Categories
Find more on Matrix Indexing 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!