How to get x2fx as a function suitable for mat lab coder?

2 views (last 30 days)
I am trying to get the x2fx of matrixA. When using Matlab coder, it says that x2fx is not supported for standalone code generation. So I decided to write a separate function that produces the x2fx according to the number of columns in matrixA.
I want to be able to produce the x2fx of up to 3 columns in matrixA.
During my testing, my matrixA is set as 9 by 2. When I tried to convert my function using the matlab coder, I get an error saying "Index expression out of bounds. Attempted to access element 3. The valid range is 1-2."
It seems my if-else function did not work. I even tried using case-switch, but the same thing happened. My matrixA is a variable that can change. It is only 9x2 for testing purposes. How can I get rid of this error?
if NumofColumns==2
QuadDesignMatrix = zeros(NumofRows,6);
for ii = 1:NumofRows
x1=matrixA(ii,1);
x2=matrixA(ii,2);
QuadDesignMatrix(ii,:) = [1 x1 x2 x1*x2 x1^2 x2^2];
end
return
elseif NumofColumns==3
QuadDesignMatrix = zeros(NumofRows,10);
for ii = 1:NumofRows
x1=MatrixA(ii,1);
x2=MatrixA(ii,2);
x3=MatrixA(ii,3);
QuadDesignMatrix(ii,:) = [1 x1 x2 x3 x1*x2 x1*x3 x2*x3 x1^2 x2^2 x3^2];
end
return
else
error=1;
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!