Компилятор по умолчанию исключает файлы данных MATLAB ® (MAT-файлы) из анализа зависимостей. См. раздел Анализ зависимостей с использованием компилятора MATLAB.
Если требуется, чтобы компилятор явно проверял данные в MAT-файле, необходимо указать %#function pragma при написании кода MATLAB.
Например, при создании решения с помощью Deep Learning Toolbox™ необходимо использовать %#function pragma в вашем коде, чтобы включить зависимость от gmdistribution класс, например.
Если развернутое приложение использует файлы данных MATLAB (MAT-файлы), рекомендуется выполнить код LOAD и SAVE управление данными и их сохранение для последующей обработки.
Использовать isdeployed чтобы определить, выполняется ли код в рабочей области MATLAB или нет.
Укажите файл данных с помощью WHICH (чтобы найти его полное имя пути) определить его относительно расположения ctfroot.
Все MAT-файлы остаются неизменными после mcc бежит. Эти файлы не шифруются при записи в развертываемый архив.
Дополнительные сведения о развертываемых архивах см. в разделе Развертываемый архив.
См. раздел ctfroot справочная страница для получения дополнительной информации о ctfroot.
Используйте следующий пример в качестве шаблона для управления данными MATLAB внутри и вне MATLAB.
В следующем примере указаны три файла данных MATLAB:
user_data.mat
userdata\extra_data.mat
..\externdata\extern_data.mat
Перейти к .matlab_root\extern\examples\compiler\Data_Handling
Собрать ex_loadsave.m со следующими mcc команда:
mcc -mv ex_loadsave.m -a 'user_data.mat' -a
'.\userdata\extra_data.mat' -a
'..\externdata\extern_data.mat'
ex_loadsave.m
function ex_loadsave
% This example shows how to work with the
% "load/save" functions on data files in
% deployed mode. There are three source data files
% in this example.
% user_data.mat
% userdata\extra_data.mat
% ..\externdata\extern_data.mat
%
% Compile this example with the mcc command:
% mcc -m ex_loadsave.m -a 'user_data.mat' -a
% '.\userdata\extra_data.mat'
% -a '..\externdata\extern_data.mat'
% All the folders under the current main MATLAB file directory will
% be included as
% relative path to ctfroot; All other folders will have the
% folder
% structure included in the deployable archive file from root of the
% disk drive.
%
% 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');