Standalone compiled with Matlab compiler doesn't work
Mostrar comentarios más antiguos
I have compiled a .exe file of MRiLab (https://se.mathworks.com/matlabcentral/fileexchange/45456-mrilab-v1-2-1) using Matlab compiler.
The program is an excellent MRI-Simulator with which you can, for example, load different phantoms and image them with different MRI sequences and imaging parameters.However, the compiled exe from MRiLab does not work as it does in Matlab. Standalone application of program starts but does not work fully. For example, when I select an MRI sequence the program gives an error message (when the exe is started in Matlab):
Error using DoParseXML (line 60)
Failed to read XML file C:\Users\sylisiur\AppData\Local\Temp\sylisiur\mcrCache9.9\MRiLab1\MRiLab\PSD\3D\FastSpinEcho\PSD_FSE3D\PSD_FSE3D.xml.
Error in SeqList>Seq_listbox_Callback (line 272)
Error in gui_mainfcn (line 95)
Error in SeqList (line 94)
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)SeqList('Seq_listbox_Callback',hObject,eventdata,guidata(hObject))
Error using waitforallfiguresclosed (line 16)
Error while evaluating UIControl Callback.
Sometimes the program lets you select some of a sequences, but when I then press the scan button it gives a new error message:

To correct the error, I have tried e.g. change the MCR_CACHE_ROOT to another path that also did not help or delete the mcrcache9.9 folder and run the program again. The versions of Matlab (R2020b) and Runtime (v9.9) also match. Apparently the problem, I think, is with the DoParseXML function (code below)?
I have been trying for a long time to solve the problem and I would be very grateful if someone could help?
BR: S.Y
function theStruct = DoParseXML(dnode)
%DoParseXML(XML_filename)
%convert XML file to a MATLAB structure.
try
tree = xmlread(dnode);
catch me
error('Failed to read XML file %s.',dnode);
end
% Recurse over child nodes. This could run into problems
% with very deeply nested trees.
theStruct = parseChildNodes(tree);
theStruct.current=1;
% ----- Subfunction PARSECHILDNODES -----
function children = parseChildNodes(theNode)
% Recurse over node children.
children = [];
if theNode.hasChildNodes
childNodes = theNode.getChildNodes;
numChildNodes = childNodes.getLength;
allocCell = cell(1, numChildNodes);
children = struct('Name', allocCell,...
'Attributes', allocCell,...
'Data', allocCell,...
'Children', allocCell,...
'current', allocCell);
i=0;
for count = 1:numChildNodes
theChild = childNodes.item(count-1);
c = makeStructFromNode(theChild);
if isempty(c)
i=i+1;
else
children(count-i) = c;
end
end
if i>0
children(numChildNodes-i+1:numChildNodes)=[];
end
end
% ----- Subfunction MAKESTRUCTFROMNODE -----
function nodeStruct = makeStructFromNode(theNode)
% Create structure of node info.
PC=parseChildNodes(theNode);
nodeStruct = struct('Name', char(theNode.getNodeName),...
'Attributes', parseAttributes(theNode),...
'Data', '',...
'Children', PC,...
'current',0);
if any(strcmp(methods(theNode), 'getData'))
nodeStruct.Data = char(theNode.getData);
else
nodeStruct.Data = '';
end
if strcmp(nodeStruct.Name,'#text')
nodeStruct=[];
end
% ----- Subfunction PARSEATTRIBUTES -----
function attributes = parseAttributes(theNode)
% Create attributes structure.
attributes = [];
if theNode.hasAttributes
theAttributes = theNode.getAttributes;
numAttributes = theAttributes.getLength;
allocCell = cell(1, numAttributes);
attributes = struct('Name', allocCell,...
'Value', allocCell);
for count = 1:numAttributes
attrib = theAttributes.item(count-1);
attributes(count).Name = char(attrib.getName);
attributes(count).Value = char(attrib.getValue);
end
end
Respuesta aceptada
Más respuestas (3)
Sam Y.
el 30 de Abr. de 2022
4 comentarios
Bruno Luong
el 30 de Abr. de 2022
Editada: Bruno Luong
el 30 de Abr. de 2022
Not necessary, you can store file with relative path to your exe file or mfile. It's up to you to organize where your file is located. I have this function that I put somewhere one level seeper than my main app, and I call to retrive the path of my main app.
function currentDir = getcurrentdir
% currentDir = getcurrentdir
if isdeployed % Stand-alone mode.
[~, result] = system('set PATH');
currentDir = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
else % MATLAB mode.
thisfile = mfilename('fullpath');
currentDir = fileparts(fileparts(thisfile)); % adjust accordingly to on your source folder structure
end
PS: Please do not post your comments as answers.
Steven Lord
el 30 de Abr. de 2022
Not necessary, you can store file with relative path to your exe file or mfile.
That I believe is true for data files, but if the app is looking to add directories containing executable code (MATLAB script, function, or class files) to the application at runtime that will not work in a standalone application. Only code included in the application when it is compiled can be called by the application.
Bruno Luong
el 30 de Abr. de 2022
OP has issue with xml file, which is a data file.
Sam Y.
el 1 de Mayo de 2022
Image Analyst
el 30 de Abr. de 2022
0 votos
Have you exhausted all the suggestions in the FAQ:
Categorías
Más información sobre Package MATLAB Functions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!