Компилятор исключает файлы данных MATLAB® (MAT-файлы) из анализа зависимостей по умолчанию. Смотрите Анализ зависимостей.
Если вы хотите, чтобы компилятор явным образом смотрел данные в файле MAT, необходимо задать %#function прагма при записи кода MATLAB.
Например, если вы создаете решение с Deep Learning Toolbox™, необходимо использовать %#function прагма в рамках вашего кода, чтобы включать зависимость от 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');