0

I am trying to mex a file in a script. The C file which has to be mexed is generated in one of the previous steps of the script before it is mexed.

When I use the below line in the script, everything works fine and the script runs successfully.

mex (strcat(component_name,'_s_func','.c'));

but when I add the same line below with

mex -g (strcat(component_name,'_s_func','.c'));

it gives me the error

C:\PROGRA~2\MATLAB~1\BIN\MEX.PL: Error: '(strcat(component_name,_s_func,.c))' not found.

Any idea why its not able to find the same file while using -g while it can find it when using without -g option?

hbaderts
  • 14,136
  • 4
  • 41
  • 48
Arun Kumar
  • 103
  • 13

2 Answers2

3

The problem with your statement is that with the syntax

mex -g [...]

MATLAB assumes you are calling mex with the string arguments '-g' and '[...]' so it assumes that your file is called (strcat(component_name,'_s_func','.c')) and does not execute the command.

You can either use the solution you posted with eval, as that way you again call it with the strings '-g' and 'filename.c'. Another possibility would be to use the syntax

mex('-g',strcat(component_name,'_s_func','.c'));

because that way the command strcat is really executed before calling mex.

--

This is the same behavior as e.g. with clear. As you might know, the following statements are equal:

clear a b c
clear('a','b','c');
hbaderts
  • 14,136
  • 4
  • 41
  • 48
  • 1
    Yes to the functional syntax. Using eval is silly here. – chappjc Apr 14 '15 at 15:36
  • but i still don't understand why not eval. why is your solution better than eval?? why both are not same . and thanks for this info. i accepted your answer already – Arun Kumar Apr 15 '15 at 10:55
  • 1
    @ArunKumar Because `mex` is itself a function, so you just have to call it like a function. That is far easier to understand and less error prone then constructing a string to execute with `eval`. Just my opinion. – chappjc Apr 15 '15 at 17:42
-2

ok its possible to do this with eval command

file_name=(strcat(component_name,'_s_func','.c'));
eval(['mex -g ',file_name]);
Arun Kumar
  • 103
  • 13