"Undefined function or method" in the Matlab Engine command window

I work with Visual Studio in C ++ code, and I send some variables to the MATLAB engine. There are no problems so far. Imagine that I have a MATLAB command window open and these variables:

Β» whos Name Size Bytes Class Attributes QWe 1x365 2920 double QWp 1x364 2912 double QWu 1x364 2912 double 

I can use the standard MATLAB functions, but I loaded a new .m function (which works in MATLAB, usually after setting the path) that this command window from the MATLAB mechanism does not recognize or cannot find.

 Β» isnormq(Q) ??? Undefined function or method 'isnormq' 

I thought that they (command window and MATLAB) are synchronized, but now I see that it is not.

How can I solve this problem so that I can use my .m function from the command line? Any help would be appreciated.

+4
source share
2 answers

As it was a long time ago and no one answered, I will post what I did:

In Matlab, every time you need newtoolbox, you bind this path once and remain there forever. You can use the functions from the toolbar as if they were the default in Matlab.

Using the Matlab mechanism, this does not work, so you need to write a command line:

 % Here we load the toolbox for converting quaternion to Euler Angles addpath(genpath('C:\Program Files (x86)\MATLAB\R2010a\toolbox\SpinCalc')); //for example 
+3
source

It has been a long time, but I ran into the same problem and found interesting information about it.

First of all, in the new version of MATLAB (2016a), the search path is MATLAB Engine C: \ Program Files \ MATLAB \ R2016a (or the same path on which you install MATLAB). Therefore, if you do not change it, C ++ can use all the built-in functions. In addition, you can use the functions from Toolboxes!

But there is another problem: what about custom functions? Therefore, I need to place the .m file directly in C: \ Program Files \ MATLAB \ R2016a to make it visible to the MATLAB Engine.

Here we can go the other way - just add the path to your .m file in MATLAB via C ++:

 char CommandChangePath[MAX_PATH]; strcpy(CommandChangePath, "addpath('C:\\Users\\SuperUser\\Documents\\Visual Studio 2017\\Projects\\MyCppProject')"); engEvalString(ep, CommandChangePath); 

It’s very useful for me to put the desired MATLAB function in the current C ++ project, add the path and use it! Now you do not need to change the path at every step - it is always remembered and always useful for the current application.

0
source

Source: https://habr.com/ru/post/1391625/


All Articles