Standalone application error
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi all,
I have this script that performs some calculations and then by command saves the data from the previous created .mat file to a .txt file. i have another script that is called when i press the "save" button in the GUI figure to save the .txt file. Now, my problem arises when i compile all this, in the standalone application when i press "save" it doesn't create the .txt file and returns an error sound.
This is my script for saving the data and that is called when "save" button is pressed:
file=get(handles.file_name,'string');
[~, name, ~] = fileparts(file);
j=load(name,'-mat');
txt= {'Longitudinal young modulus'};
tempfile = 'results.txt';
fid = fopen(tempfile,'w');
for i = 1:length(txt)
fprintf(fid,'%s\n',txt{i});
end
fclose(fid);
dlmwrite('results.txt', num2str(j.E1),'delimiter', '','roffset',1,'coffset',2,'-append');
Is anything in here that is not compilable?
Thank you
0 Commenti
Risposta accettata
Image Analyst
il 17 Nov 2011
You didn't get the folder of your file. And with compiled apps, they don't live where you think they do - in the folder where your executable lives, they actually live in some temporary folder. Issue the command
fprintf('Current folder = %s\n', ctfroot);
to see where this really is. You did not install your folder there obviously because there was no way for you to know where that was until you ran the program and got the ctfroot string value.
It's almost never a good practice to assume files will be in the current directory, and it's even more so when you have compiled programs. You NEED to make sure you know at all times the folder where your files live. Your edit field apparently does not contain the full path and has just the basefilename. Then you don't prepend a path, the KNOWN path, where you expect the file to be. Hence your error - you're not looking in the right place when you call load(). Make sure you use fullfile() and exist(, 'file'), and try and catch, and find out what ctfroot is. Also call Mathworks and ask them to explain to you what the environment variable MCR_CACHE_ROOT is. Compiling is very tricky and I don't have time now for a full tutorial. Finally, make sure you check out the FAQ:
0 Commenti
Più risposte (1)
Titus Edelhofer
il 17 Nov 2011
Hi,
assuming you are using Windows, I'd suggest to open a dos window (run "cmd" from Windows Start), navigate to where the .exe is and run the executable. Then you should see the error message of the application ...?
Titus
0 Commenti
Vedere anche
Categorie
Scopri di più su MATLAB Compiler in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!