codegen: problems with output arguments of function
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to convery legacy MATLAB code into C code and am running into some problems.
function [yr, yi] = module do_something(xr, xi, bitrate)
x = complex(x1, x2);
// etc etc do some stuff get back y as a complex number
yr = real(y);
yi = imag(y);
end
I split up the imaginary and real parts as I am running MATLAB R2015a and there is a note that the wrapper function does not support complex types.
My problem is output varsize
yr and yi are 2-dimensional arrays that can vary in size. If I don't specify anything, my generated C-code creates an int * yr_size[2] and int * yi_size[2]. I read the contents of the array and the first element contains the number of rows and the second array was always 0.
After reading up, I decided to use coder.varsize. I got an error from codegen saying that variable input/output varsize is not supported.
To work around this, I create 2 fixed arrays of max size, yr_padded and yi_padded. Then, after all my calculations, I copy yr and yi into their respective fixed arrays and pass that as the output to the argument.
function [yr_padded, yi_padded] = module do_something(xr, xi, bitrate) #codegen
x = complex(x1, x2);
// etc etc do some stuff get back y as a complex number
yr = real(y);
yi = imag(y);
yr_padded = zeros(7, 800000);
yi_padded = zeros(7, 800000);
for i = 1:size(yr, 1)
for j = 1:size(yr, 2)
yr_padded(i,j) = yr(i,j);
end
end
for i = 1:size(yi, 1)
for j = 1:size(yi, 2)
yi_padded(i,j) = yi(i,j);
end
end
end
Is there a more elegant way to do this? What exactly is happening with yr_size and yi_size?
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Algorithm Acceleration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!