I compiled a script that uses the tcpip function from the instruments toolbox using MCR_R2015a. Running the generated executable on the PC I used for compiling (Windows7) is not a problem, however running it on another PC (Windows10, no Matlab installed) is. I receive the following error:
unknown variable com or unknown class com.mathworks.toolbox.instrument.TCPIP
pointing to line 123 in tcpip. The surrounding code is:
try
obj.jobject = handle(com.mathworks.toolbox.instrument.TCPIP(host,port));
catch aException
newExc = MException('instrument:tcpip:cannotCreate',aException.message);
throw(newExc); %%% this is line 123
end
Obviously com.mathworks.toolbox.instrument.TCPIP is not known. I tried to find the file defining this object to append it when compiling without success.
Where to find that file or how to compile a running executable?
As I was able to run the script inside Matlab but not the executable using the Matlab compiler runtime, I figured an unset path in the MCR may cause the error.
Not being able to find the file were the path to the TCPIP class is defined, I ended up deinstalling the MCR. Et voilá, it worked!
I am aware this solution is not answering the question how to compile scripts containing the tcpip function and running the generated exe on PCs that have no Matlab installed. But it is good enough for me.
Related
I am using an external solver to run simulations. I am trying to call the external solver with system(cmd) from a MATLAB script. The cmd itself runs fine with no problems from the Terminal (I'm running on OSX). However, every time the MATLAB script runs, the status is 139 - Segmentation Fault. Does anyone know why this might be happening?
When executing the system command this is not the same as running a program from the terminal since you likely have environment variables defined within your terminal session (via ~/.bashrc or ~/.bash_profile) that are going to effect how a program is accessed and run.
If you have environment variables that you need to set for the program to run successfully, use setenv from within MATLAB prior to calling system.
I had the same problem with my Matlab (R2016b), but the solution was exactly the opposite.
Instead of missing variables, system() defined LD_LIBRARY_PATH which redirected to some shared libraries packaged with Matlab that didn't sit well with my program. After clearing LD_LIBRARY_PATH in my script, everything worked fine. You can do that for example with this:
env -u LD_LIBRARY_PATH
I need to use a toolbox in Matlab that depends on a external program written in C and using OpenCV. I'm using Ubuntu 14.04 64 bits and Matlab R2014b.
The m-script calls it with the system function and after the C program runs, it reads some output files that the C program should generate. This is failing to happen. I observed that the files are not being generated.
Then, the first thing I did was verify if the C program was working properly, by directly calling it in the terminal, with the same parameters that the m-script has used to call it. Then it worked and the files where generated. Thus, the C program is correct and working.
Coming back to Matlab, it failed again. Then, I started debugging the C program and had find out that the OpenCV function cvLoadImage is failing to open the file, when called from Matlab. It works if I call it outside.
I verified the string that is passed to the function both running from Matlab and externally and it is rigorously the same, but the Matlab call fails ever. I verified with ldconfig -p | grep opencv from the Matlab command window and it shows the libraries. More amusing, there are other calls to other ocv functions before the problematic one that are working. Just this is failing.
The question is: is this a problem of some misconfiguration of my part or maybe it is a bug in Matlab?
Thanks in advance.
EDIT
Actually, calling from inside Matlab with sudo appended to the system call got the job done. What is strange, because I used chmod 777 -Rf as last resource in the whole folder and verified that my user was the owner of both the folder and Matlab processes. Strange... It stills bothers me having to type my password whenever I use the script though, but my schedule is tight, I'll consider this workaround as satisfactory by now.
Instead of calling the C function from MATLAB, you can try to call MATLAB from your C code with MATLAB Engine API for C:
https://es.mathworks.com/help/matlab/calling-matlab-engine-from-c-programs-1.html
I have always been able to use the MATLAB function block on simulink without problems, but ever since yesterday it has been giving me the message
Unable to locate a C-compiler required by Stateflow and MATLAB Function blocks.
Use 'mex -setup' to select a supported C-compiler.
After some search I tried installing Windows SDK, and reinstalling Microsoft Visual C++ 2010 Express, but the error persists.
When I run the simulink model the following message appears on MATLAB's main window, before the first message appears on simulink
Warning: ''MySQL' is not recognized as an internal or external
command,
operable program or batch file.
'MySQL' is not recognized as an internal or external command,
operable program or batch file.
VSINSTALLDIR'
exceeds MATLAB's maximum name length of 63 characters and has
been truncated to
''MySQL' is not recognized as an internal or external command,
o'.
I don't know if it they are connected, but the only recent change I made in this computer was installing MySQL in it.
Assuming you're using windows (which it looks like from the question), type !where mysql on the Matlab command prompt. If the result is blank, you've got a path issue. Let's fix it.
First off, locate where your mysql executable lives -- either type where mysql.exe in a command shell, or just find it on the filesytem. Let's assume it's in C:\Path\To\Mysql\. Then, on the Matlab command prompt, change the PATH system variable by running:
setenv('PATH', [getenv('PATH') ';C:\Path\To\Mysql\']);
Hopefully, that will work.
For a project I am working on I'm preparing data in MATLAB, then running the data through a separate external application (written in C++) named Model v2.exe, then performing further analysis with the output in MATLAB. I'm trying to create an M-file which does all of this, but I am struggling to get the C++ program to launch from my MATLAB code.
How can I launch an external application from within my MATLAB code?
You can either make use of the ! operator, or the system() command.
First, rename you application to something that has no spaces in the name, like modelv2.exe. Next, either make sure it is in the system path, as defined by your system environment variables, or generate a full path to it (eg: C:\Users\Phil\Desktop\modelv2.exe).
You can call an executable program from the command line using the exclamation point or the system command:
!modelv2
or:
!C:\Users\Phil\Desktop\modelv2.exe
will cause Windows to execute the program hello.exe if there is such a file in the current directory or on the system path. Alternatively:
system('modelv2');
or
system('C:\Users\Phil\Desktop\modelv2.exe');
will do the same thing.
References
"MATLAB Central - call and run an external program in matlab under windows", Accessed 2014-03-19, <http://www.mathworks.com/matlabcentral/answers/11568-call-and-run-an-external-program-in-matlab-under-windows>
I compiled some Matlab code on Centos 5.
I try to run it like this:
run_cnaseq006.sh /projects/rcorbettprj2/mutationSeq/MCR/v714/ "/home/rcorbett/slx_service_rc/etc/cnv_test_data/CNV_test/config.m"
------------------------------------------
Setting up environment variables
---
LD_LIBRARY_PATH is .:/projects/rcorbettprj2/mutationSeq/MCR/v714//runtime/glnxa64:/projects/rcorbettprj2/mutationSeq/MCR/v714//bin/glnxa64:/projects/rcorbettprj2/mutationSeq/MCR/v714//sys/os/glnxa64:/projects/rcorbettprj2/mutationSeq/MCR/v714//sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/projects/rcorbettprj2/mutationSeq/MCR/v714//sys/java/jre/glnxa64/jre/lib/amd64/server:/projects/rcorbettprj2/mutationSeq/MCR/v714//sys/java/jre/glnxa64/jre/lib/amd64/client:/projects/rcorbettprj2/mutationSeq/MCR/v714//sys/java/jre/glnxa64/jre/lib/amd64
??? Error using ==> run at 65
/home/rcorbett/slx_service_rc/etc/cnv_test_data/CNV_test/config.m not found.
However, I can easily see that the file does exist:
ll /home/rcorbett/slx_service_rc/etc/cnv_test_data/CNV_test/config.m
-rw-r--r-- 1 rcorbett users 3 Aug 13 09:10 /home/rcorbett/slx_service_rc/etc/cnv_test_data/CNV_test/config.m
I tried different quotes, and no quotes, but I can't figure out why it won't execute the file. The Code works fine as uncompiled matlab code, so something funny is happening after compilation that affects the ability to identify the file.
EDIT: run_cnaseq006.sh is the auto generated shell script for running my compiled code. It is about 40 lines, so doesn't copy well into here. However, I can say it is just a wrapper to make sure all the libraries are loaded when I run my compiled code. All the compiled code I have get pretty much the exact shell script wrapper.
I was pointed to this link:
http://blogs.mathworks.com/loren/2008/08/11/path-management-in-deployed-applications/
The "run" command uses path management functions like "cd". According to the above article such activities are unsupported in compiled applications, and can create unpredictable results.
I resigned to using an alternate approach to define my runtime variables by reading the file with getline and using "eval" to load my variables into memory.