Error in Compiled exe, but running in m file MATLAB - matlab

I have build a program that run properly in m file MATLAB. but when I compile to exe using Matlab compiler, some function didn't work. here is the error command window show on matlab execute program
undefined function or method 'maple' for input arguments of type 'char'
error in ==> function_a at 5
codes on function_a.m is
function function_a(msg)
format long
%parameter p & q
maple('z1:=',randint(1,1,[12 20])); %these run in m.file, but not in exe compile
p=maple('nextprime(z1)');
p=str2double(p);
is there any solution for that?please need your advice, many thanks

Assuming you have tried to compile the version from exactly this sourcecode and that you call it twice with exactly the same input, it appears that MATLAB simply does not realize that the function maple will be used by you.
I have had this before with some project, eventually I decided to use the 'add additional resource to project' option in deploytool.
Depending on your needs you can either just add the function, or the folder containing this function.

The command maple is from Symbolic Toolbox, which is not supported by MATLAB Compiler. You will not be able to successfully compile and run your program.
What's happened is that the maple command is not allowed to be compiled, so when the .exe runs, it can't find the function maple, and gives you the error you're seeing. It would be nice if MATLAB gave you a more informative error message, but it seems it doesn't.

Related

MATLAB C S-function cannot be compiled in simulink real time

I used C S-function in Simulink real time. When compiling the model, the following errors occurred,
“mxCreateDoubleScalar”is not defined;
“mexPutVariable”is not defined;
<"mxSetCell_ is_ not_ supported_ in_ Simulink_ Coder ": undeclared identifier
[enter image description here][1]
I know that Simulink real time doesn't seem to support “mxCreateDoubleScalar”、“mexPutVariable”, but I don't know how to replace it, can you help me?
[1]: https://i.stack.imgur.com/xtiyo.png
I recommend you to work with executables. First you have to have installed a C/C++ compiler. I recommend you to install minGW (you can get it on the AddOn of Matlab).
Then, you have to initialize all the variables that you are using on the s-function.
For last, when you want to make a "mex" with your model and s-function, check the command line to mex all files. I had the same problem 2 years ago and I was able to create a real-time application and run it.
Here you have how to use the mex function mex function
Here you have the information about the C/C++ compiler C/C++ compiler
Here you have the information about how configurate your .mdl or .slx Simulink Real-Time
I suggest you to post this question on the Matlab's forum, possibly they could help you better.
BR.
PD: If you have .h files linked with your .c file, make sure that on the mex command line you are linking all this files.

How to change the MATLAB path back to the default?

I was trying to add a toolbox in MATLAB and instead of calling addpath('path'), I called path('path').
Now I'm getting a lot of errors, like
if I initialize a variable, I get
Error using eval. Undefined function 'workspacefunc' for input arguments of type struct
Is there anyway I can restore the default MATLAB path/paths ?
Use the MATLAB command
restoredefaultpath
to restore the MATLAB search path to the state at startup.
See MATLAB documentation for restoredefaultpath here
I had a similar situation where on startup, on Windows 8.1 64-bit, Matlab R2014b would show the same error and then no function would work.
In my case, restoredefaultpathcouldn't be found.
Setting the UserPath in the matlab setting file as suggested elsewhere also didn't help.
The solution was to remove the environment variable MATLABPATH that I had set as a convenience while trying to compile against Matlab libraries.
The error message could be more helpful...

How do I use the lteRMCDL tool?

I'm following an example from MathWorks.
When I run the code I get an erroneous output
Error in Untitled3 (line 38)
rmc = lteRMCDL(enb, ncw);
If the error you describe was preceded by:
Undefined function 'lteRMCDL' for input arguments of type 'struct'.
Then the most likely reason is that you do not have the LTE system toolbox, or that you have an older version which does not contain that function.
You can check which version of MATLAB you are running, and all the installed toolboxes you have along with their version number, by typing ver at the command line. Alternatively , you can check the location of a given function on the path by typing which lteRMCDL (this can help if the problem is that you have written a function with the same name as an existing MATLAB function, or if your MATLAB path is not set up correctly).
MATLAB online help shows by default the latest (2013b at time of writing) help and requires you to log in to show archived help files.

matlab parfor with arrayfun (sliced variable)

As the title says, I want to have a parfor loop with inside usage of arrayfun.
I created a minimal working example for the problem:
Having the following lines in a file called thisparfortest.m
function test=thisparfortest(countmax)
parfor count=1:countmax
test(count).nummer=count;
test(count).bisdrei=arrayfun(#(testnum)eq(test(count).nummer,testnum),1:3);
end
the command mcc('-e','-v','thisparfortest') results in
Compiler version: 4.18.1 (R2013a)
Error: File: **************\thisparfortest.m Line: 3 Column: 5
The variable test in a parfor cannot be classified.
See Parallel for Loops in MATLAB, "Overview".
Processing C:\Program Files\MATLAB\R2013a\toolbox\matlab\mcc.enc
Processing include files...
2 item(s) added.
Processing directories installed with MCR...
The file mccExcludedFiles.log contains a list of functions excluded from the CTF archive.
0 item(s) added.
Generating MATLAB path for the compiled application...
Created 43 path items.
Parsing file "****************\thisparfortest.m"
(Referenced from: "Compiler Command Line").
Parsing file "C:\Program Files\MATLAB\R2013a\toolbox\compiler\deploy\deployprint.m"
(Referenced from: "Compiler Command Line").
Parsing file "C:\Program Files\MATLAB\R2013a\toolbox\compiler\deploy\printdlg.m"
(Referenced from: "Compiler Command Line").
Unable to determine function name or input/output argument count for function
in MATLAB file "thisparfortest".
Please use MLINT to determine if this file contains errors.
Error using mcc
Error executing mcc, return status = 1 (0x1).
but as advised mlint thisparfortest (and also checkcode) returns no problems - like in the editor.
The loop can be done and compiled as a for loop.
Please do not ask for the sense of these commands - they are just here for the mwe.
I think, this should be reported to mathworks - or have I done something wrong?
Some additions:
When running
function retval=thisparfortest(countmax)
helpfun=#(x)arrayfun(#(testnum)eq(x,testnum),1:3);
parfor count=1:countmax
retval(count).nummer=count^2;
retval(count).bisdrei=helpfun(retval(count).nummer);
end
with only the for loop it works, but when using the shown version with parfor it results in
Error using thisparfortest>(parfor supply) (line 3)
Undefined function or variable "retval".
Error in thisparfortest (line 3)
parfor count=1:countmax
Caused by:
Undefined function or variable "retval"
Shouldn't that be caught by mlint/checkcode? This happens without compiler.
I don't believe the issue has anything to with compilation. When I attempt to run your code in regular MATLAB I get the same error that the variable test in a parfor cannot be classified.
There's no bug here - not every piece of code can be run inside a parfor loop, and it's not possible for MATLAB to perfectly determine prior to runtime which pieces can and can't. It tries to do a good job, and when it does, the Code Analyzer will tell you prior to runtime - but when it can't, it will give a runtime error as you've found.
Perhaps you can think of a way that MATLAB could have statically determined that this variable could not be classified - in that case this could be reported to MathWorks as an enhancement request to Code Analyzer.

Mex or Compile (mcc) Matlab function that uses toolkits

Environment:
Matlab R2012a (I have access to others if necessary)
All Toolboxes/Compiler installed
Ubuntu 12.04 64bit and/or Windows 7 64bit
I am working with the source for a software package written in Matlab (unfortunately its proprietary so no code examples...sorry), and one function briefly uses the Control System Toolbox and the Signal Processing Toolbox.
I have no problem running the code on my personal computer because I have every toolbox installed, however I would like to compile (mex or mcc) JUST the function using those two toolboxes. The goal, of course, is to run the software on a machine without those toolboxes, while leaving the remaining code open to change.
According to matlab, they have no problem with you compiling code that uses almost any toolbox. Here is the list of toolboxes that support mcc compilation:
http://www.mathworks.com/products/compiler/supported/compiler_support.html
The problem arises in that mcc no longer allows compiling with the -x option to create a mex-ed version of the function, so I'm forced to create a C executable (maybe? hopefully not). This particular function takes large matrices as parameters (impractical to write as a command line argument) and returns a structure of cell arrays.
The only way around this (as I see it now) would be to write the arguments (large matrices) to the hard drive in a binary .mat file , have the compiled C binary read in the arguments, run the algorithm, and finally save the return values in another .mat for the parent thread to load back into memory.
This seems totally impractical. I would greatly appreciate alternative suggestions. Please let me know if anything here in unclear. Thanks in advance!
[Edit 1] The codegen package does not support tf.m. It seems like this should be possible (and used to be possible with the mex -x option), but I'm at a loss. Any suggestions would be greatly appreciated!
I think the reason -x is not supported anymore is the fact that Matlab now has a product called "coder", which converts .m files to .c files and can also create .mex files from "suitable" .m files using the option -args to specify the input arguments: http://www.mathworks.com/videos/generating-c-code-from-matlab-code-68964.html