Inefficient C code generated from Real Time Workshop Embedded Coder

3 Ansichten (letzte 30 Tage)
Om
Om am 24 Feb. 2014
Bearbeitet: Walter Roberson am 24 Feb. 2014
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

Antworten (0)

Kategorien

Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by