Subscript indices must either be real positive integers or logicals
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to optimize a function with nonlinear constraints. and the constraints function is as follows:
function [c,ceq]=mycon(X)
persistent Fgrrz Fgrlz xdata fourier
c=[min(fourier(X(1:11),xdata));1.8-min(fourier(X(1:11),xdata));max(fourier(X(12:22),xdata))-1.7;1.1-min(fourier(X(12:22),xdata));max(fourier(X(23:33),xdata));...
-3*pi/2+fourier(X(23:33),xdata);max(fourier(X(34:44),xdata));-min(fourier(X(34:44),xdata))-1.1;max(-Fgrrz);max(-Fgrlz)];
ceq=[];
end
but I am getting this error that "Subscript indices must either be real positive integers or logicals." what was going wrong?!
2 comentarios
Geoff
el 1 de Abr. de 2012
You omitted the most important part of the error message. On which line does the error occur?
Respuestas (5)
Geoff
el 1 de Abr. de 2012
How can fourier be a function when you just defined it as a persistent variable in your mycon function? I suspect you may be misusing the persistent keyword. Perhaps you meant to use global.
Perhaps you meant this:
function [c,ceq]=mycon( X, Fgrrz, Fgrlz, xdata )
And wrap it with an anonymous function for passing to your solver:
mycon_objective = @(x) mycon( x, Fgrrz, Fgrlz, xdata );
1 comentario
Geoff
el 1 de Abr. de 2012
By the way, I am implying here that you remove the 'persistent' line entirely, and pass your data into your function. The wrapper allows this to happen, while maintaining the original function's calling syntax.
Image Analyst
el 1 de Abr. de 2012
Look at this part: fourier(X(1:11),xdata) What are fourier, X and xdata? First of all, fourier appears to be an array but it never appears to get assigned ever. None of the other 3 persistent variables seems to ever get assigned either. Then you're trying to look at the X,xdata elements but if X and xdata are not integers or logicals this doesn't make sense. How can you look at the 3.5th, 8.9th element of the array? It would need to be the 3,8 element or some similar integer designation.
By the way, why return ceq when it's always null?
0 comentarios
hadi
el 1 de Abr. de 2012
4 comentarios
Geoff
el 3 de Abr. de 2012
Define the function Fourier just as you have defined mycon. If the Fourier function is only relevant within mycon, then you can put it in the same file - no other functions will be able to see it. If you want it to be visible to other functions, define it in a file called Fourier.m
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display 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!