Info
This question is closed. Reopen it to edit or answer.
When I compile the GUI, a problem occured
1 view (last 30 days)
Show older comments
Hi, I've just finished my GUI and tried to compile it as an .exe file (by deploytool). The program works but one part of the program gives an error. The suprising thing that, in GUI it works well but in .exe it doesn't. Here is the code, maybe you can help me;
try
nmat3=handles.nmat;
akorlar=chordlist5(nmat3,chord_chan_no);
[n,m]=size(akorlar);
a=0;
for k=1:n
liste(1+a,:)=findchordyazi(akorlar(k,1),akorlar(k,2),akorlar(k,3),akorlar(k,4));
a=a+1;
end
fid=fopen('Akorlar.txt','w');
for i=1:length(liste)
fprintf(fid,'%s\r\n',liste(i,:));
end
fclose(fid);
system('Akorlar.txt')
catch
helpdlg('Bu midide akor bulunmuyor veya yanlış bir kanal değeri seçtiniz','İşlem Sonucu')
end
As you understood the code, simply it is for listing some words in a text file. It always gives me the warning message on the helpdlg line. Whereas it shouldn't be happened.
Thanks
0 Comments
Answers (2)
Image Analyst
on 28 Mar 2014
This is not going to work:
fid=fopen('Akorlar.txt','w');
unless you are absolutely sure what the current folder is. I strongly recommend you not just assume everything is going to be in the current folder, because it's not. The current folder is not where your exe is. Your exe is not even there - it's actually in some hidden secret folder. Put a "pwd" in your code if you want to know where it is. You'll be surprised. To fix, make sure you use fullfile() to specify the full filename.
if ~exist(fullFileName , 'file')
message = sprintf('Error: file does not exist:\n%s', fullFileName);
uiwait(warndlg(message));
return;
end
fullFileName = fullfile('c:\whatever', 'Akorlar.txt');
fid=fopen(fullFileName ,'w');
if fid ~= -1
% Process the file......
Use a try catch like this that gives more info:
try
% Some code that might generate an error.
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(1, '%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
Finally, check out the FAQ for more ideas: http://matlab.wikia.com/wiki/FAQ?title=FAQ&cb=728#My_standalone_executable_won.27t_run_on_the_target_computer._What_can_I_try.3F
0 Comments
Huseyin
on 29 Mar 2014
Edited: Huseyin
on 29 Mar 2014
3 Comments
Image Analyst
on 29 Mar 2014
The point is, we don't know why your code went into the catch statement. And once it's there, it gives virtually no useful information, unlike my catch code which gives you the full error message and line of code that it failed on. Perhaps you should just use the old, brute force approach of printing stuff between every line of code to figure out the offending line. Before every line of code, put
fprintf('About to call fullfile...\n');
fullFileName = fullfile('c:\', 'Akorlar.txt');
fprintf('About to call fopen...\n');
fid=fopen(fullFileName ,'w');
fprintf('About to start the for loop...\n');
for i=1:length(liste)
and so on until you find out what line it is.
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!