Inefficient C code generated from Real Time Workshop Embedded Coder

조회 수: 3 (최근 30일)
Om
Om 2014년 2월 24일
편집: Walter Roberson 2014년 2월 24일
I am using Matlab R2008a on Mac.
Here is some example code to illustrate how inefficient the generated C code is:
function [dataStruct,dataStruct2,csum,csum2] = testFunc() %#eml
dataStruct = struct('array',ones(10,3,5),'csum',zeros(10,3,5));
dataStruct2 = struct('array',ones(10,3,5),'csum',zeros(10,3,5));
csum = zeros(10,3,5);
csum2 = zeros(10,3,5);
vars = [1 2 3 4 5];
divisor = [1 2 3];
for i = 1:5
for k = 1:3
dataStruct2.array(vars(i),k,i) = dataStruct2.array(vars(i),k,i)+3;
dataStruct2.array(:,k,i) = dataStruct2.array(:,k,i)/divisor(k); *bold*
end
end
Here is the generated C code corresponding to the division step:
for(eml_i0 = 0; eml_i0 < 10; eml_i0++) {
eml_b_dataStruct2[eml_i0] = eml_dataStruct2->array[(eml_i0 + 10 * eml_k)
+ 30 * eml_i] / (real_T)eml_B;
}
for(eml_B = 0; eml_B < 10; eml_B++) {
eml_dataStruct2->array[(eml_B + 10 * eml_k) + 30 * eml_i] =
eml_b_dataStruct2[eml_B];
}
This code is creating a copy of the output in eml_b_dataStruct2, and then copies that into the output variable eml_dataStruct2->array. I would like for the generated code to look like this:
for(eml_i0 = 0; eml_i0 < 10; eml_i0++) {
eml_dataStruct2->array[(eml_i0 + 10 * eml_k)
+ 30 * eml_i] = eml_dataStruct2->array[(eml_i0 + 10 * eml_k)
+ 30 * eml_i] / (real_T)eml_B;
}
Is this something that has been fixed in newer versions of Matlab?
Regards

답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by