how to overcome this error Index exceeds array dimensions. Index value 2 exceeds valid range [1-1] of array x.
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
srinivasan ravi
el 7 de Nov. de 2018
Respondida: Anurag Kammari
el 16 de Jun. de 2022
i am trying to find the skewness value of fft data by setting up the window of width 50 so that it calculates for each window to determine the highest peak(above threshold). I am doing this in Simulink where I directly give input to Matlab function block and getting this error. can you guide me with my code, please.
%main code
function result_k1= fcn(u)
x=[];
x=[x;u];
result_k1=zeros(100,1);
window_width=50;
for j=1:100
window_m1=x((j:window_width+(j-1)));
window_m11=window_m1(:);
result_k1(j)=skewness(window_m11);
end %#codegen end
0 comentarios
Respuesta aceptada
TADA
el 8 de Nov. de 2018
Seems like your input is shorter than your function expects.
You must take the size of u in account when you decide the number of iterations in your loop and the window size, you can have that width 50 as an upper limit, and the index vector j should not exceed the length of u
1 comentario
Más respuestas (1)
Anurag Kammari
el 16 de Jun. de 2022
function [Sa,Sb,Sc,Tp1] = control(T_ref,sflux_ref,wm,i_meas,Ts, Lm, Lr, Ls, Rs, kr, t_sigma, tr, r_sigma, v, states, p, lambda)
persistent x_opt Fs
if isempty(x_opt),x_opt = 1;end
if isempty(Fs),Fs = 0+0i*1;end
Fs = Fs+Ts*(v(x_opt)-Rs*i_meas);
Fr = Lr/Lm*Fs+i_meas*(Lm-Lr*Ls/Lm);
g = zeros(1,19);
for i = 1:19
v_01 = v(i);
Fsp1 = Fs+Ts*v_01-Rs*Ts*i_meas;
Isp1 = (1+Ts/t_sigma)*i_meas+Ts/(t_sigma+Ts)*...
(1/r_sigma*((kr/tr-kr*1i*wm)*Fr+v_01));
Tp1 = 3/2*p*imag(conj(Fsp1)*Isp1);
g(i)=abs(T_ref-Tp1)+lambda*abs(sflux_ref-abs(Fsp1));
end
[~,x_opt] = min(g);
Sa = states(x_opt,1);
Sb = states(x_opt,2);
Sc = states(x_opt,3);
Caused by: Index exceeds array dimensions. Index value 3 exceeds valid range [1-1] for array 'states'. Error in 'PTCL3/Controller' (line 17) Sa = states(x_opt,1);
0 comentarios
Ver también
Categorías
Más información sobre Simulink Functions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!