I have convert my .m file(a function) to .exe file, and i run the .exe file from cmd like this:
Now i want to get the path of exe file automatic(in this example it is D:\test\),how can i get it?

 채택된 답변

Walter Roberson
Walter Roberson 2016년 12월 21일

0 개 추천

댓글 수: 6

Real Name
Real Name 2019년 6월 15일
편집: Real Name 2019년 6월 15일
"Newsreader is no longer available"
This is why even if answers are duplicated, at least give a copy of the answer rather than just linking.
@StackOverflow, @Piazza
Walter Roberson
Walter Roberson 2019년 6월 16일
This is not StackOverflow or Piazza .
I have posted over 65000 responses. Stopping to copy in all of the relevant documentation at each point would have taken a lot of extra time.
It would also have involved copying in a lot of copyrighted materials, almost certainly involving more copying than is permitted by the case law on proportions permitted to be copied under the Fair Use clauses in USA copyright law. The portions of that case law that deal with copying larger sections are strictly for analysis and criticism -- which is to say that you have to actively analyze everything copied and respond to it or discuss how it all holds together and how it compares to other ideas. USA copyright law does not permit technical material to be copied in bulk just to make it convenient to access the material if the primary link becomes inaccessible.
Walter Roberson
Walter Roberson 2019년 6월 16일
편집: Walter Roberson 2019년 6월 16일
15 posts by 6 different authors. Under copyright law, before I could copy the material here, I would have to obtain permission from all 6 authors. I am certain I can contact 2 of them, and suspect I know how to locate another 2 of them, and just might be able to contact 1 more of them, but I doubt I can contact the remaining author.
E Swan
E Swan 2020년 5월 12일
I wonder how many of those 65000 answers are now useless because they only contain a dead link
Walter Roberson
Walter Roberson 2020년 5월 12일
I don't know at the moment, but you are welcome to count them yourself.
Walter Roberson
Walter Roberson 2020년 5월 15일
E Swan: the number that are "now useless because they only contain a dead link" is low. When you click on a view_thread link, the page that you are taken to now includes a link to the relevant Google Groups discussion.

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

Image Analyst
Image Analyst 2016년 12월 21일

3 개 추천

See my attached function.

댓글 수: 3

Image Analyst
Image Analyst 2016년 12월 21일
See discussion of MCR_CACHE_ROOT.
Try setting your MCR_CACHE_ROOT environment variable to dot.
This will make it unpack the CTF to your app's folder on your deployed/target computer. Yes, it will clutter up that folder with stuff but now any files you deployed will most likely be found, whereas they might not be if you used the wrong code to get the folder where your actual executable lives. Remember the executable your users run is actually like a shell program that unpacks a bunch of stuff, including the actual executable, to some secret folder. And it is that executable that actually gets run. So there are two folders, or even more. The one given by pwd. The one given by mfilename('fullpath'). And the one given by ctfroot. And there are even more folders than that. Granted, it's a confusing mess.
Bogdan Dzyubak
Bogdan Dzyubak 2018년 7월 21일
Where should the MCR_CACHE_ROOT be set? Would I have setenv(MCR_CACHE_ROOT,'.') as part of the compiled code, or is there a different method?
Image Analyst
Image Analyst 2018년 7월 21일
That should be fine. If you don't set it, it picks some hidden place, like maybe something under c:\users somewhere. If you do that then you need to make sure you use the -a option to include any files you need to load at runtime. If you use dot, then you can put them as subfolders of your installation folder and put them there with a third party installer (like I do).

댓글을 달려면 로그인하십시오.

edit
edit 2016년 12월 22일
편집: Stefanie Schwarz 2024년 10월 21일

1 개 추천

Thank you for your help. I have solve the problem by add the showpath.m into my function .m file then convert it to .exe. The detail of showpath.m file is like this:
function [thePath]=showpath()
% Show EXE path:
if isdeployed % Stand-alone mode.
[status, result] = system('set PATH');
thePath = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
else % Running from MATLAB.
thePath=pwd;
end
return
José-Luis
José-Luis 2016년 12월 21일

0 개 추천

댓글 수: 2

edit
edit 2016년 12월 21일
It seem no work,and i think what i want to do just something like mfilename(it seem just work in .m file not in .exe file).
José-Luis
José-Luis 2016년 12월 21일
"It seem no work" doesn't really help us understand what the problem is. Could you show what is the result you expect and what you use as input?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

질문:

2016년 12월 21일

답변:

2024년 10월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by