Help with parsing code

1 view (last 30 days)
Aditi Akula
Aditi Akula on 10 Jun 2015
Commented: Walter Roberson on 11 Jun 2015
Hi
I want to parse the matlab code using Coder
following matlab code
function abc(arg1, aarg2)
m1('string1', data.struct.field1);
m1('string2', data.struct.field2);
m1('string3', data.struct.field3);
function m1(handle1, handle2)
if(not(strcmp(coder.target,'')),
%use handle2 to generate some required calcs and code
else
% use handle1 to print some stuff to a csv file.
end
Everytime I parse the above code, the coder generates C code for function abc() as follows
void abc(handle2){
m1(data.struct.field1);
b_m1(data.struct.field2);
c_m1(data.struct.field3);
}
the problem is it generated multiple copies of the same function 'm1' because the string input is different in matlab code. How can I ignore the string input when I am parsing and just have one function definition irrespective of the string inputs.
Thanks a lot.
Aditi.

Answers (2)

Walter Roberson
Walter Roberson on 11 Jun 2015
m1strings = {'string1', 'string2', 'string3'};
m1fields = {'field1', 'field2', 'field3'};
for K = 1 : length(m1strings)
m1(m1strings{K}, data.struct.(m1fields{K}));
end

Aditi Akula
Aditi Akula on 11 Jun 2015
Hi Walter,
Thank you for the reply.
I have 1000's of these function calls m1('string3', data.struct.field3);
so your answer may not be feasible for us.
Can we somehow tell Matlab to 1) either ignore the string input 2) or send it as a pointer so the content of the string is not considered so that the parser can generate only one function.
Else, it will be a lot of manual work for us. And we want to automate the process.
Any of you inputs will be really valuable.
Thank you Aditi.
  1 Comment
Walter Roberson
Walter Roberson on 11 Jun 2015
Sorry, I do not have experience with that.

Sign in to comment.

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!