codegen: problems with output arguments of function
1 回表示 (過去 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!