How can I fix the error: Index exceeds the number of array elements (1)?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Voss
2023-3-16
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!