0

Is there any work around for using the "import" function when coverting a matlab *.m file to a C++ executable?

Matlab gives me this response: "Import statements are currently unsupported." and I just wanted to know if I was SOL or not.

Thanks

Alex
  • 87
  • 7

1 Answers1

3

import makes Java classes available to Matlab programs. Since doing so makes it necessary to actually have a running Java Runtime Environment, I think it would be very costly to provide this functionality to generated C++ code – while it is always present when running the original m-file. I therefore would interpret the error message to say exactly what it says: "unsupported".


To be more precise and give references: MATLAB Language Features Supported for C/C++ Code Generation explicitly says that Java is not supported, but Matlab classes are. Moreover, import is not contained in the list of Functions Supported for C/C++ Code Generation.

A. Donda
  • 8,381
  • 2
  • 20
  • 49
  • What about when `import` is used to import another MATLAB package? – Mohsen Nosratinia Oct 15 '13 at 17:12
  • Good point, I missed that additional functionality. I guess this should work, but I really don't know. – A. Donda Oct 15 '13 at 17:15
  • I'm importing these functions: import com.comsol.model.* and import com.comsol.model.util.* which I think might be java classes – Alex Oct 15 '13 at 17:22
  • You can check by looking at the directories where these classes are installed. Compiled Java classes are in files with the extension .class, while Matlab classes appear to be directories containing m-files. – A. Donda Oct 15 '13 at 17:26
  • yea, they look like JAR files. Thank you for your help then! – Alex Oct 15 '13 at 17:31
  • @Mohsen, since `import` is not supported generally (see edited answer), this implies that it can't be used for Matlab packages either. I suppose it is possible to use Matlab OOP without packages? – A. Donda Oct 15 '13 at 18:54