"Index in position 1 is invalid"
1 次查看(过去 30 天)
显示 更早的评论
Hello,
running this code always returns the error "Index in position 1 is invalid. Array indices must be positive integers or logical values.".
The error is located in the line expressing obj_1.
It's seems to be independent from the for cycles since the same happens if I try to run the line outside.
obj_1 = @(p) 0;
for jj=1:5 %peaks
n = 40;
for ii = (floor(omega_r_idx_1(jj))-n):(floor(omega_r_idx_1(jj))+n) %funzione obiettivo su un intervallo n punti prima e dopo
obj_1 = @(p) obj_1(p) + ((real (H1(freq(ii),5)) -real((freq(ii)^2*p(jj,1))+p(jj,3)./(p(jj,2).^2-freq(ii)^2+...
2*1i*p(jj,4)*p(jj,2).*freq(ii))+p(jj,5))))^2+((imag(H1(freq(ii),5)) -imag((freq(ii)^2*p(jj,1))+p(jj,3)./(p(jj,2).^2-...
freq(ii)^2+2*1i*p(jj,4)*p(jj,2).*freq(ii))+p(jj,5))))^2;
end
end
I already tried to evaluate all the parameters like H1, freq and omega_r_idx_1 in the specified indexes and it works.
Could you please help me?
6 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!