I can not open a file with Guide after compilation
Afficher commentaires plus anciens
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
Geoff Hayes
le 14 Mai 2020
Mickael - how is the code trying to read the file? Are you providing the full path to the file?
Mickael
le 14 Mai 2020
Walter Roberson
le 14 Mai 2020
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
le 14 Mai 2020
Mickael
le 14 Mai 2020
Geoff Hayes
le 14 Mai 2020
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.
Walter Roberson
le 14 Mai 2020
[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
le 14 Mai 2020
Réponses (0)
Catégories
En savoir plus sur MATLAB Compiler dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!