MATLAB: How can i correct the subscript of a vector in a for loop

matlab function

Hi
I want to plot X=f(wr) but i have this error
Subscript indices must either be real positive integers or logicals.
Knowing that mr,damping,kr are matrix(40*40)
And my program is :
Damping=(2*zeta*kr)/(6600*pi);
F=[zeros(39,1);ones(1,1)];
IIw=linspace(5,10,40);
wr=IIw*2*pi;
for w=wr(1):wr(40)
X(w)=(-w.^2*mr + j*w*Damping + kr)\ F;
end
plot(wr,abs(X))

Best Answer

Your problem is that you are inxexing X with w, which may be a decimal.
To correct it, use:
ind = 0;
for w=wr(1):wr(40)
ind = ind+1;
X(ind)=(-w.^2*mr + j*w*Damping + kr)\ F; %%you were indexing X(w)
end