主要内容

MATLAB数据文件在编译应用程序

明确包括MATLAB数据文件使用% #函数编译指示

MATLAB编译器不包括®默认数据文件(mat文件)依赖性分析。看到使用MATLAB编译器依赖分析

如果你想让编译器垫中显式地检查数据文件,您需要指定% #函数当编写MATLAB代码编译指示。

例如,如果您正在创建一个与深度学习工具箱™解决方案,您需要使用% #函数编译指示包括依赖在你的代码gmdistribution类,例如。

加载和保存功能

如果您的部署的应用程序使用MATLAB数据文件(mat文件),它有助于代码负载保存函数来操作数据并将其存储为以后处理。

  • 使用isdeployed来确定你的代码运行在或MATLAB工作区。

  • 通过使用指定的数据文件哪一个(来定位它的完整路径名称)的位置相对于定义它ctfroot

  • mat文件都不变世纪挑战集团运行。这些文件写入时,并未加密部署归档。

更多信息可部署的档案,知道了可部署的存档

看到ctfroot更多信息参考页面ctfroot

使用下面的例子作为操纵MATLAB数据的模板里面,外面,MATLAB。

使用加载/保存功能流程MATLAB部署的应用程序的数据

下面的示例指定三个MATLAB数据文件:

  • user_data.mat

  • 用户数据\ extra_data.mat

  • . . \ externdata \ extern_data.mat

  1. 导航到matlab_root\走读生\ \编译器\ Data_Handling例子

  2. 编译ex_loadsave.m用下面的世纪挑战集团命令:

    mcc mv ex_loadsave。m - a”user_data。垫“——”。\用户数据\ extra_data。垫”——“. . \ externdata \ extern_data.mat”

ex_loadsave.m

函数ex_loadsave %这个例子展示了如何使用%”加载/保存”功能在数据文件%部署模式。有三个源数据文件%在这个例子。% user_data。垫%用户数据\ extra_data。垫% . . \ externdata \ extern_data。垫% %与mcc命令编译这个例子:% mcc - m ex_loadsave。m - a”user_data。垫——%。\用户数据\ extra_data。垫. . \ externdata \ extern_data“%——”。垫' %所有当前主MATLAB文件目录下的文件夹%将作为ctfroot %相对路径;所有其他文件夹有%文件夹%结构部署归档文件中包含的根%磁盘驱动器。 % % If a data file is outside of the main MATLAB file path, % the absolute path will be % included in deployable archive and extracted under ctfroot. For example: % Data file % "c:\$matlabroot\examples\externdata\extern_data.mat" % will be added into deployable archive and extracted to % "$ctfroot\$matlabroot\examples\externdata\extern_data.mat". % % All mat/data files are unchanged after mcc runs. There is % no encryption on these user included data files. They are % included in the deployable archive. % % The target data file is: % .\output\saved_data.mat % When writing the file to local disk, do not save any files % under ctfroot since it may be refreshed and deleted % when the application isnext started. %==== load data file ============================= if isdeployed % In deployed mode, all file under CTFRoot in the path are loaded % by full path name or relative to $ctfroot. % LOADFILENAME1=which(fullfile(ctfroot,mfilename,'user_data.mat')); % LOADFILENAME2=which(fullfile(ctfroot,'userdata','extra_data.mat')); LOADFILENAME1=which(fullfile('user_data.mat')); LOADFILENAME2=which(fullfile('extra_data.mat')); % For external data file, full path will be added into deployable archive; % you don't need specify the full path to find the file. LOADFILENAME3=which(fullfile('extern_data.mat')); else %running the code in MATLAB LOADFILENAME1=fullfile(matlabroot,'extern','examples','compiler', 'Data_Handling','user_data.mat'); LOADFILENAME2=fullfile(matlabroot,'extern','examples','compiler', 'Data_Handling','userdata','extra_data.mat'); LOADFILENAME3=fullfile(matlabroot,'extern','examples','compiler', 'externdata','extern_data.mat'); end % Load the data file from current working directory disp(['Load A from : ',LOADFILENAME1]); load(LOADFILENAME1,'data1'); disp('A= '); disp(data1); % Load the data file from sub directory disp(['Load B from : ',LOADFILENAME2]); load(LOADFILENAME2,'data2'); disp('B= '); disp(data2); % Load extern data outside of current working directory disp(['Load extern data from : ',LOADFILENAME3]); load(LOADFILENAME3); disp('ext_data= '); disp(ext_data); %==== multiple the data matrix by 2 ============== result = data1*data2; disp('A * B = '); disp(result); %==== save the new data to a new file =========== SAVEPATH=strcat(pwd,filesep,'output'); if ( ~isdir(SAVEPATH)) mkdir(SAVEPATH); end SAVEFILENAME=strcat(SAVEPATH,filesep,'saved_data.mat'); disp(['Save the A * B result to : ',SAVEFILENAME]); save(SAVEFILENAME, 'result');