主要内容

MATLAB已编译应用程序中的数据文件

明确包括MATLAB数据文件使用%#函数Pragma

编译器不包括Matlab®默认情况下,从依赖关系分析中的数据文件(MAT文件)。看依赖关系分析

如果希望编译器显式地检查MAT文件中的数据,则需要指定% #函数pragma当你写你的MATLAB代码。

例如,如果您正在使用Deep Learning Toolbox™创建一个解决方案,您需要使用% #函数您的代码中的Pragma包含依赖性GMDistribution.例如,类。

加载和保存功能

如果您部署的应用程序使用MATLAB数据文件(MAT-files),那么编写代码会很有帮助加载保存函数以操纵数据并将其存储以供以后处理。

  • 使用isdeployed以确定代码是在MATLAB工作空间内运行还是在MATLAB工作空间外运行。

  • 使用。指定数据文件哪一个(找到其完整路径名)将其定义相对于位置ctfroot.

  • 所有MAT文件都是不变的MCC.运行。这些文件在写入可部署存档时没有加密。

有关可部署档案的更多信息,请参阅可部署档案

看看ctfroot.有关的更多信息,请参考网页ctfroot.

使用以下示例作为MATLAB内部和外部的MATLAB数据的模板。

使用Load/Save函数来处理MATLAB部署应用程序的数据

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

  • user_data.mat.

  • 用户数据\ extra_data.mat

  • . . \ externdata \ extern_data.mat

  1. 导航到matlab_root.\ extern \ mixing \ compiler \ data_handling

  2. 编译ex_loadsave.m有以下内容MCC.命令:

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

ex_loadsave.m

这个例子展示了如何在% deployed模式下使用数据文件上的% "load/save"函数。在本例中有三个源数据文件%。% user_data。垫%用户数据\ extra_data。垫% . . \ externdata \ extern_data。使用mcc命令编译这个示例:% mcc -m ex_loadsave。m - a”user_data。在这里输入“-a %”。mat' % -a '..\externdata\extern_data。在当前的MATLAB主文件目录下的所有文件夹将%包含为%相对路径到ctfroot;所有其他文件夹都将% folder %结构包含在可部署的归档文件中,来自%磁盘驱动器的根目录。 % % 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');