MATLAB Coder indexing out of bounds
3 views (last 30 days)
function f = objctiv(x)
here x has x1..x10 values. For above function if i try to acsess x2,..x10 it gives error.
Attempted to access element 2. The valid range is 1-1.
how can i grow matlab variables through indexing,Which can be supported by MATLAB Coder. Please suggest me how it could be done.
I found following link for similar problem.
how can i do sugggested thing for my problem.
Mike Hosea on 9 Jul 2013
If x is a scalar passed to this function, then attempting to reference x(2) will error in MATLAB and in MATLAB Coder in exactly the same way for exactly the same reason. This has nothing to do with growing an array by indexing. I suspect you have tried to compile this without specifying the type of x using -args or through the coder GUI. Once you correct that issue, you need to preallocate f by
f = zeros(1,2,class(x));
Now that is because growing arrays by indexing is unsupported. Note that preallocation is preferred in MATLAB.