Code generation specific output array size

조회 수: 2 (최근 30일)
Emrah Duatepe
Emrah Duatepe 2018년 7월 16일
댓글: Emrah Duatepe 2021년 2월 24일
hello, I am trying these codes that below
function [ Mshifted, f] = Func1( m ,ts,df)
fs = 1/ts;
Mshifted = zeros(1,4096);
f = zeros(1,4096);
[M,m1,df1]=fftseq(m,ts,df);
M=M/fs;
f=[0:df1:df1*(length(m1)-1)]-fs/2;
Mshifted = abs(fftshift(M));
end
and I obtain that prototype
void Func1(const double m[4096], double ts, double df, emxArray_real_T *Mshifted,emxArray_real_T *f);
How can I get array that it has 4096 size.Because in C ,this is problem especially in MCU you know because of fragmentation.emxArray_real_T include in struct is data* and if I use any emxArray_real_T abc; definition ,program give an interrupt about array size and shut down.By the way I am trying in Qt Creature those codes.Do you know any book about code generation examples and applications,and any offer about specific errors and workings

답변 (1개)

Denis Gurchenkov
Denis Gurchenkov 2018년 7월 19일
I think your question is "How can I get Mshifted and f to have size 4096 in the generated C code"?
With that presumption, if you use subscripted assignment, the size of the variable will be preserved. Change the last two lines of your code to:
f(:) = [0:df1:df1*(length(m1)-1)]-fs/2;
Mshifted(:) = abs(fftshift(M));
and now f and Mshifted are both 1-by-4096 because of the previous assignments with explicit sizes.
Another way to solve this is to modify fftseq so that it returns a fixed-size array, using same technique -- preallocate the output of the right size, and then use sub-assign to assign the first part of the array the output of fft.
hth,
Denis
  댓글 수: 1
Emrah Duatepe
Emrah Duatepe 2021년 2월 24일
Hi Denis, I know this is very late response but thank you for help :). I was just checking my questions list and I have seen that no response ,sorry for that.

댓글을 달려면 로그인하십시오.

카테고리

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

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by