Standalone executable is not reading files from the same directory

Hi,
I am trying to create a standalone executable using the application compiler. The main script takes in the data from a file the same directory, then does some algebra with it and saves it in another file in the same directory. The following is a simple version of the code I have in mind.
disp('Start Script');
data = importdata('InputFile.dat');
NewData = data*5;
save('OutputFile.mat', 'NewData');
disp('End Script');
However, when I run the standalone executable it reads the data that was present in the InputFile.dat at the time when the executable was created. It does not read the contents of the file at the time when I ran the application. Further, after running the code, I cannot locate the output file as well. How do I make the standalone application read contents from the InputFile at real time as well as save the file in real time?

 採用された回答

Walter Roberson
Walter Roberson 2021 年 8 月 7 日

0 投票

Question for you:
When you launch a standalone executable from an icon: what is the "current directory" for the executable?

3 件のコメント

Roshan Mathew Tom
Roshan Mathew Tom 2021 年 8 月 7 日
編集済み: Roshan Mathew Tom 2021 年 8 月 7 日
I used ctfroot within the script and I gives me the following directory:
\Users\admin\AppData\Local\Temp\admin\mcrCache9.9\TestFu19
I get the issue now. The Inputfiles is located in this directory, so I would need to go to this directory and change them to the user values. However, that looks cumbersome. Is there any way that I would create a standalone executable that takes the input files from where the icon/exe file is located?
Thanks
Walter Roberson
Walter Roberson 2021 年 8 月 7 日
Determining where the original exe is located is not simple, but might be possible.
However, the recommendation is instead to use uigetfile() to find out where the user wants to read the files from. You can use it together with the preferences facility such as setpref() so that after the first time, you could remember where the user wants the files to be.
You could also have a hierarchy of locations. For example if you have multiple users using the same executable, then you might want to first look in a particular subdirectory of the user's home directory to see if the input exists, and if it does not, then look in a shared local directory... and possibly if it is not there, then look on a network share...
Roshan Mathew Tom
Roshan Mathew Tom 2021 年 8 月 9 日
I replaced InputFile.dat with .\InputFile.dat and it worked.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB Compiler についてさらに検索

製品

リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by