我正在从 Matlab 编码器生成 C 代码。 我有一个功能如下
function C = foo( A, B ) %#codegen
for j=1:100,
C = C+A(j);
end
end
这个函数在c中生成的代码是
void foo(float A[100],B,float* C){
for(j=0;j<100;j++){
*C+=A[j];
}
}
我希望代码高效并按以下方式生成:
void foo(float* A,B,float* C){
//here B is the length of the array
for(j=0;j<B;j++){
*C+=*(A+j);
}
}
你有什么想法吗?
最佳答案
我不明白整个故事,但你为什么不更改你的 matlab 代码以实际使用 B
作为开始并告诉我们然后发生了什么,比如
function C = foo( A, B ) %#codegen
for j=1:B,
C = C+A(j);
end
end
关于c - Matlab高效代码生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9211871/