MATLAB standalone program data source

1 回表示 (過去 30 日間)
Seum Bin Rahman
Seum Bin Rahman 2019 年 8 月 11 日
コメント済み: Walter Roberson 2019 年 8 月 11 日
I have built a MATLAB standalone program. The original MATLAB program is supposed to import data from an excel file named P2.xlsx. After converting it to Standalone, if in change values in P2.xlsx, the output does not change.
How can I make it work?

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 8 月 11 日
I suspect that you had a file by that name when you built the executable, and that the file got bundled with the executable and is the one being used.
You should read about ctfroot()
Executables do not generally look in the current directory for files. Well, they do, but they look in ctfroot first, and the current directory is seldom where you expect. Standalone executables operate as graphics programs opened by Windows, and so there is no way for them to pick up the user's current directory because there is a different current directory for every graphics program.
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 8 月 11 日
https://www.mathworks.com/help/compiler/ctfroot.html
Walter Roberson
Walter Roberson 2019 年 8 月 11 日
Generally you should proceed one of a few ways:
  1. uigetfile to interact with the user to select the file. Flexible but not always as convenient
  2. uigetfile but then use setpref to record the location so that next time you can retrieve it. I am not sure if the preferences would be cleared if the expanded ctf is removed
  3. use windows environment variables to locate the user's home directory or application directory and store the files there. Beware that not all users have their home directory on C:, especially in a networked environment.
  4. hardcode the path to the file. This gets risky as different environments use different directory structures.

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

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by