MATLAB Answers

Using Matlab compiler which(filename) can not locate file

4 views (last 30 days)
Nevine on 30 Apr 2020
Commented: Nevine on 18 Jun 2020
I'm compiling into an executable a matlab function that includes a which() finction:
str = which(filename)
The file is on the path and the function returns the file location successfully if I run from matlab but does not work if I compile the app into an executable.
This works in 2018B but stopped working in 2020A.
This seems to be a bug in 2020A. Any suggestions for a workaround?


Sign in to comment.

Answers (2)

Chidvi Modala
Chidvi Modala on 12 Jun 2020
I tried generating executable for the following piece of code in MATLAB R2020A
function code()
filename = 'abc.m';
str = which(filename);
It worked fine. Can you elaborate on what error you were getting and code you were trying to run?


Sign in to comment.

Steven Lord
Steven Lord on 12 Jun 2020
What are you planning on doing with that information?
If you're planning to use this to try to run a function the user provides when running the executable, this will not work.
If you're using this to try to locate a data file, you should read this documentation page.
Also, what does "stopped working" mean in this context?
  • Do you receive warning and/or error messages?
  • Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
  • Does your application crash? If so please send the crash log file (with a description of what you were running or doing in the executable when the crash occured) to Technical Support using the telephone icon in the upper-right corner of this page so we can investigate.

  1 Comment

Nevine on 18 Jun 2020
Thanks for the reply and we have resolved the issue. The file is being used as a marker file to determine the path to assembly dlls needed for our application. The which() function is being called from within the Matlab App Designer. The code is then compiled to an executable using the Matlab compiler. The issue is that the which command was returning an empty string as it was failing to locate the file. It seems that the file was not included in the compiler project file as part of the auto generation from the code analysis. Once we included it manually, it is able find the path. Thanks again!

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!