How can I get the alternatives for the functions Not supported by Matlab Coder?

29 次查看(过去 30 天)
Dear All,
I want to convert my Matlab code into C language using Matlab Coder. But I got the following functions which are Not Supported by Matlab Coder. I have to find the alternatives for those functions. The functions are:
exist, sscanf, regexp, mkdir, cd, addpath, str2num, quit, ismembc, mat2cell, cellfun, split.
Does anyone have an idea how to get the alternatives for above functions?
Thanks a lot in advance. You all have a good weekend!
Benson
  2 个评论
John D'Errico
John D'Errico 2021-7-23
There may be good reasons why some of them are not supported. You would need to write those codes yourself, from scratch. Good luck on some of them. :)
Benson Gou
Benson Gou 2021-7-24
Hi, John,
Thanks for your suggestions. Do you think if it is possible for me to get the Matlab code of the above functions?
Thanks a lot again.
Benson

请先登录,再进行评论。

采纳的回答

Steven Lord
Steven Lord 2021-7-24
which exist
built-in (/MATLAB/toolbox/matlab/lang/exist)
There is no purely MATLAB code equivalent for this. You could probably use file I/O functions in C to check if the file exists (does opening the file succeed?) See the section on External Code Integration for how to call C or C++ functions from your MATLAB code. See in particular the examples on the documentation page for coder.ceval for how to call MATLAB code when you're not generating code and C code when you are.
which sscanf
built-in (/MATLAB/toolbox/matlab/strfun/sscanf)
I think you could substitute scanf in C. Alternately you could parse the char vector yourself and use str2double to turn character vectors representing numbers into numbers.
which regexp
built-in (/MATLAB/toolbox/matlab/strfun/regexp)
There is no purely MATLAB code equivalent for this. Any such MATLAB equivalent you would write would likely be quite complicated, unless you targeted it solely at the portion of the regular expression language you were using.
which mkdir
built-in (/MATLAB/toolbox/matlab/general/mkdir)
There is no purely MATLAB code equivalent for this. C has the capability to create directories.
which cd
built-in (/MATLAB/toolbox/matlab/general/cd)
I'm not sure C really has the concept of a current directory, so you're probably going to need to rethink this.
which addpath
/MATLAB/toolbox/matlab/connector2/shadowfiles/shadows/addpath/addpath.m
While this is in MATLAB code, C doesn't have the concept of a MATLAB search path. You're going to need to rethink this.
which str2num
/MATLAB/toolbox/matlab/strfun/str2num.m
Consider str2double instead.
which quit
built-in (/MATLAB/toolbox/matlab/general/quit)
There is no purely MATLAB code equivalent for this. Just have your application exit.
which ismembc
built-in (/MATLAB/toolbox/matlab/ops/ismembc)
You could write a set membership function that loops through the two vectors, but you would need to write that.
which mat2cell
/MATLAB/toolbox/matlab/datatypes/mat2cell.m
This is MATLAB code, but I think how to convert it would depend on what you're doing with those cells.
which cellfun
built-in (/MATLAB/toolbox/matlab/datatypes/cellfun)
See mat2cell.
which split
/MATLAB/toolbox/matlab/strfun/split.m
This could probably be done via a loop, but again what are you planning to do with those cells or with that string array?
As for your question "Do you think if it is possible for me to get the Matlab code of the above functions?" most of those are not implemented using MATLAB code. For those that are, the solution is unlikely to be as simple as copying the text of those functions in place of the function calls in your application.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by