필터 지우기
필터 지우기

MATLAB Coder indexing out of bounds

조회 수: 4 (최근 30일)
sita
sita 2013년 7월 9일
Hi,
function f = objctiv(x)
f(1)=x(1).^2-2*x(2).^2 f(2)=x(10).^2
end
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.
Thanks, Sita

답변 (1개)

Mike Hosea
Mike Hosea 2013년 7월 9일
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.

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by