Updating a data file for a compiled application
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a matlab application that uses a .mat file where the database is stored. When I create the application I included the .mat file and it creates the standalone application.
The thing is that sometimes I need to update the .mat file, and until now I haven't found a way to just replace the .mat file without the need to compile the application again. I tried including the .mat file in the "Files installed for your end user" section. But it seems the application does not read that file anyway, when I change it the old data is shown.
thank you
댓글 수: 0
답변 (1개)
Walter Roberson
2016년 9월 26일
The files you include get bundled as part of the .exe, so you do need to rebuild to update the file.
You could write your code so that it looked for the file somewhere in a user directory first, and read it from there if it finds it; then you could just distribute the new .mat file to users (who would have to put it in the appropriate location.)
댓글 수: 3
Walter Roberson
2016년 9월 27일
That happens when you add the .mat file to the project using the GUI or the -a command line switch.
In a compiled application, when you load() using a filename that is not fully qualified, no matter what your MATLAB path variable is set to, the ctfroot directory is always tried first. Therefore if you want to try loading from a user directory or a known location, you need to fully qualify the filename. For example you might look at the APPDATA environment variable using getenv('APPDATA'), or put together HOMEDRIVE and HOMEPATH; or you might use the userpath() function -- though I do not know how userpath() works for deployed applications. Anyhow, you would use
try
load(some_fully_qualifed_path);
catch
load(some_relative_path);
end
Though using load() in this way is not recommended! Always use load() with an output variable and pull out results from the structure created that way... making sure that you test that the variables you need exist in the file before you rely on them. (Users can be clumsy and may accidentally save random junk over top of the file...)
Kaixiang Wang
2018년 7월 6일
@Walter I have a similar problem, and loading using absolute path does solve the problem; now it reads the updated mat-file. Thank you.
@Oliver I also tried deleting the mat-file from my disk, but it works for me, and compiler will stops including it automatically.
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!