MATLAB Answers


How would these functions behave after compiling from GUI -> Executable?

Asked by Kevin Phung on 2 May 2019
Latest activity Commented on by Rik
on 2 May 2019
I have designed a matlab gui (not with guide or appdesigner) and am interested in eventually compiling it into an executable file so that other users won't be required to have matlab in order to run it.
However, I was wondering how some functionalities in my GUI would work.
  • I have a 'save' and 'load' feature in my gui where I save my class objects into a .mat file, and my load function will read from this .mat file. Will this still be possible?
  • in my GUI, i search for these .mat files to load through:
list = dir('*.mat')
because this command checks the current directory in MATLAB... I would imagine that this will not work once it is turned into an executable. Will I have to program my function to first check for the type of operating system, then look at a specific directory by accessing the terminal? (for example, IF mac, then 'pwd', if windows, then 'cd')


I would assume pwd will still return the current directory, which I would expect to be the directory of the executable. But wouldn't this be easy to test?
Also, when looking into a file system, use functions like fullfile and filesep to generalize your code.
Hi Rik, pwd doesnt work for a windows terminal-- 'cd' is the appropriate command. Similarly, 'dir' is for windows and the macos equivalent is 'ls,' but I have a feeling you already knew this and maybe I was a bit vague. I was wondering if I have to accomodate for these differences in how I write my callback function in my GUI, or if matlabcompiler would somehow automatically make this line:
list = dir('*.mat')
change dynamically on its own depending on the OS of the users' and i can just leave it as is.
I can't test this yet because I do not own the Matlab Compiler package, and am trying to figure out what works / what doesnt before I get it/ try the trial.
The fullfile and filesep functions you suggested do seem helpful so thank you for that :)
There is a difference between the OS command line/terminal command and the Matlab function. I would assume you don't lose access to the Matlab function dir just because you compiled your function to a MacOS executable, that simply doesn't make sense to me.
I don't own the toolboxes either, so I can't test it for you.

Sign in to comment.

0 Answers