using matlab compiler to read a .mat file at run time
Show older comments
I want to compile a. m file, which included a load statement to load a .mat file, normally it seems this .mat file is then included in the compiled .exe file and cannot change (without recompilation). However, I would like the .exe file to load the .mat file at run time so I can change the contents of the .mat file with new data values. How do I do this?
7 Comments
Jan
on 13 May 2022
How do you select the file currently in the m-file? What about a file choosing dialog?
Nick Gibson
on 13 May 2022
dpb
on 13 May 2022
Would need to see more on this -- my compiled (standalone) app loads and writes a .mat file dynamically with no issues -- the load command is in a function called from the app startupFcn(app) function that is automagically called. In this case, the .mat file contains only "behind-the-scenes" user settings for the app for restoration of state the next time is called so it is updated/rewritten only when the app is closed so the save() command is in the app close for ExitMenu,QuitButton, but a data file could be loaded/saved at will.
IOW, I don't see any such behavior with a standalone compiled app -- this was built with App Designer so has all its startup/shutdown code and all. I've not tried building something completely programmatically.
Nick Gibson
on 13 May 2022
dpb
on 13 May 2022
That's going to be dependent upon how the install is set up -- the above app also just references the file name and the installer seems to work to put the file where it needs to be.
Do you show it in the dependencies? I forget just now whether there's a way to specify the file location during the build process or not; don't recall that I had to do anything specific other than ensure it showed the dependency.
Been too long since built it the first time to remember, details precisely, otomh...
I think I do recall there being a discussion topic in the documentation on locating data files, though...dig through the app developer doc's.
Nick Gibson
on 13 May 2022
dpb
on 13 May 2022
<matlab-data-file-mat-files> is example load/save with deployed .mat files was remembering ... up one level from there is all you could want to know including the link @Jan shows...
Accepted Answer
More Answers (1)
Jan
on 13 May 2022
0 votes
Consider, that pwd is fragile. Any subfunction might change the current directory.
See here for a method to get the location of the exe file:
The ctfroot command might be useful also.
2 Comments
Nick Gibson
on 13 May 2022
Walter Roberson
on 13 May 2022
ctfroot is designed for this purpose.
Categories
Find more on C Shared Library Integration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!