I can not open a file with Guide after compilation

Good evening,
I would like to import/read a file within an application made with app designer (see a short example in attached file), however once I compile it with Application Compiler, it is not able to read it anymore. I have tried to put the file out or in the same folder as the application without success.
What do you believe I should do?
Thank you in advance,
Best regards,
Mickaël

8 commentaires

Mickael - how is the code trying to read the file? Are you providing the full path to the file?
Geoff - No I am just using the function to select it with a prompt
[FileName, PathName] = uigetfile('*.txt','Select a txt-file');
Could you confirm you are using fullfile() to put together the PathName and FileName ? If you are using [PathName FileName] then Don't Do That, as you cannot be sure that there is a path separator in what is returned from uigetfile.
Mickael
Mickael le 14 Mai 2020
Thank you Walter, however my concern is not about the PathName we could obtain with uigetfile but that when it is compiled it is not working anymore...
I built a simple *.mlapp as seen in my first message and it does not work after it is compiled. In fact, it looks that the program launch uiget file and then stopped... I do not understand why there would have a concern here.
Please find attached the test.mlapp file quite simple which works pretty well and the test.app application which is compiled and does not work anymore...
typically in the test.mlapp there is the code :
function [FileName, PathName] = Read_file(app)
nline = 0;
[FileName, PathName] = uigetfile('*.txt','Select a txt-file'); % choix du fichier à lire par l'utilisateur
wholefile = fileread(FileName); % read in entire file
newfiledata = strrep(wholefile,',','.'); % replace commas with full stops
fileid = fopen(FileName,'r'); % open file to read
while feof(fileid)==0 % End of the file reached?
readline=fgetl(fileid);
nline = nline+1;
end
end
function ReadPushed(app, event)
[FileName, PathName] = Read_file(app);
fullFileName = fullfile(FileName, PathName);
if isequal(FileName,0)
app.Logwindow.Value = 'User selected Cancel';
else
app.Logwindow.Value = strcat('User selected', ' ', fullFileName);
end
end
Mickael - in the Read_file function you may still want to use the PathName when trying to read the file. This function would then become
function [FileName, PathName] = Read_file(app)
nline = 0;
[FileName, PathName] = uigetfile('*.txt','Select a txt-file'); % choix du fichier à lire par l'utilisateur
wholefile = fileread(fullfile(PathName, FileName)); % read in entire file
newfiledata = strrep(wholefile,',','.'); % replace commas with full stops
fileid = fopen(fullfile(PathName, FileName),'r'); % open file to read
while feof(fileid)==0 % End of the file reached?
readline=fgetl(fileid);
nline = nline+1;
end
end
In the above, it isn't clear to me why you use fileread and then fopen on the same file. Do you need to do both, especially as the newfileata isn't being used?
For your second function, I see that you are using fullfile but the inputs are backwards: you are putting the filename before the path. I guess it really doesn't matter since you are only using the fullFileName variable for display purposes.
[FileName, PathName] = uigetfile('*.txt','Select a txt-file'); % choix du fichier à lire par l'utilisateur
wholefile = fileread(FileName); % read in entire file
That code would work if the file happened to be in the current directory. But when you compile an application, the default current directory is the temporary directory that the executable unpacks into; see the documentation for ctfroot() and https://blogs.mathworks.com/loren/2008/08/11/path-management-in-deployed-applications/
Mickael
Mickael le 14 Mai 2020
Thank you both of you for your comments.
@ Geoff, sorry, it is a truncated part of my main program and I forgot to remove all the useless lines to present my problem
@ Walter, I am going to look into it. Thanks

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur MATLAB Compiler dans Centre d'aide et File Exchange

Produits

Version

R2020a

Question posée :

le 13 Mai 2020

Commenté :

le 14 Mai 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by