How Can I create exe file of GUI program (.fig, .m)

Hi I have GUI matlab program (with some functions and csv file inside which I call) and I want to convert to exe. I use 'deploytool' and application compiler to do that. I read some parameters from csv file so if I change csv file, the output must change too. But it seems that it does not depend on csv file and it run with some default parameters from the previous run.
my second question is that if I have to creat exe files for all the functions which I call inside the main code or not? Thanks

Risposte (1)

Adam
Adam il 15 Giu 2018
For the second question, no, you create an exe for your top level function and it will bring in all the dependencies it needs (though you do have to add some yourself sometimes - e.g. if you call functions using str2func or some other method by which a string turns into a function.
The first question is impossible to answer without a lot more information - e.g. does it work fine before it is deployed? Are you using full file paths rather than relative file paths? How are you initialising the GUI, what code are you running when the csv file changes? etc

10 Commenti

hoda kazemzadeh
hoda kazemzadeh il 17 Giu 2018
Modificato: hoda kazemzadeh il 17 Giu 2018
First question:
Does it work fine before it is deployed? Yes it is working.
what code are you running when the csv file changes?
I have a script for changing the parameters of csv file and the file creates when I run this function. But if I change csv file manually , it is working as well without calling that function to create it. But when I convert to exe file and I run it, with or without the csv file, exe file run with the last values were set before conversion. My goal is to be able to change the parameters of csv file manually and in the main function they would be used.
Are you using full file paths rather than relative file paths I use relative path for example : readtable(configuration.scv). It is not clear for me what I have to do.
Second question:
In my second code which converted, I use str2double. That is why I have error when I run exe file? what else I have to add?
I do as following : enter deploytool to open the tool window and I choose Application Compiler. Then I add the main function and then click OK to build it. Do I miss something?
Using relative paths for a deployed executable is wrong for any user-supplied file, unless the executable is deliberately figuring out where the user files are and cd'ing to there. Please review the blog link I posted.
I read it but not vey clear. Can you give me an example how to use fullpath in my case?
while true
[filename, filedir] = uigetfile('*.csv', 'Select a csv');
if ~ischar(filename); error('User cancel'); end
fullname = fullfile(filedir, filename);
if ~exit(fullname, 'file')
uiwait(msgbox('That file does not exist ??'));
else
fid = fopen(fullname, 'r');
if fid < 0
uiwait(msgbox('File could not be opened!'));
else
break;
end
end
end
%if we got here then fid is the identifier of a readable file
I got this error when I select my file: too many output arguments.
So in the case of no error, I have to replace myfile.csv in "readtable(myfile.csv) with the identifier which I got from your last comment?
while true
[filename, filedir] = uigetfile('*.csv', 'Select a csv');
if ~ischar(filename); error('User cancel'); end
fullname = fullfile(filedir, filename);
if ~exist(fullname, 'file')
uiwait(msgbox('That file does not exist ??'));
else
break;
end
end
try
T = readtable(fullname);
catch ME
error('Could not read the file');
end
That is working perfect thanks.
there is one small issue, I use readtable in two different functions; my main function and in another one in which I generate wav files. When I run the exe file at the beginning I have to choose csv file from my desired directory that was my goal but, for the second step when I press storebutton to create wav files, again asks me to choose csv file that is not my issue. for the second one I want to read from a csv file in a specific directory which I saved my csv file already. (for example in the same folder of exe file) Is that possible?
You can save files to wherever you want if you have the file path and the folder in question has write permissions.
doc ctfroot
can be useful if you need to use a relative path in a deployed application, though you should wrap it in an
if isdeployed
block with an else to define your file path for non-deployed code if you don't wish to save relative to where ctfroot points for non-deployed code (which appears to be the Matlab install directory, which is not usually useful as a relative directory for your own files)

Accedi per commentare.

Categorie

Tag

Richiesto:

il 15 Giu 2018

Commentato:

il 19 Giu 2018

Community Treasure Hunt

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

Start Hunting!

Translated by