Storing persistent variable in a standalone GUI
4 次查看(过去 30 天)
显示 更早的评论
Hello All,
I have a GUI standalone app I've written that works beutifully in MATLAB, uncompiled. It stores several settings/user preferences in an XML file and reads them when appropriate.
The problem is, when I compile the program to use as a standalone, even using relative paths, the xml file never gets updated between uses of the application. Is there a better way to store variable persistently inbetween different instances of my application?
0 个评论
回答(3 个)
Image Analyst
2012-9-27
编辑:Image Analyst
2012-9-27
Use save() to store them in a proprietary MATLAB format file. Then use load() to retrieve them. That's what I do.
Is there any particular reason why you wanted or needed it in an XML file? Sure it's a text file, but it's not particularly easy to read or edit. I wouldn't use XML unless you needed to communicate with some other program for some reason (one that doesn't understand MATLAB's mat file format).
Also, you have to be careful where you store it. If you're trying to store it somewhere under the Program Files folder, Windows 7 won't let you. You can store files in certain places in the c:\User folder and anywhere under the c:\ProgramData folder. The ProgramData folder is a common place that Win7 apps store their initialization settings. Take a look inside yours.
0 个评论
Robert Cumming
2012-9-27
There is no reason why you shouldn't be able to update your settings in the XML file when its compiled - can you capture an error? Go old school and put lots of disp statements in your code to see where it gets to when the settings are being updated - that way you can maybe see where an error is - and hence be able to fix it.
You can launch your code from a CMD to make sure you can see any messages.
I seconds IA comment of "why XML"?
I use a human readable txt file for this purpose - why text and not standard save() - I do this so that I can quickly customise it on the fly when developing - if and when required.
0 个评论
Romesh
2012-10-3
There is a likely reason that you have this problem. When the program is compiled, you might have included the XML file inside the archive. Then when you load it, it would be using the static compiled version. The solution is to store the XML file completely independently of your program. For example, store it in a Windows application data folder (use something like %APPDATA%\yourprogram) or in a user directory (e.g. ~/.yourprogram/) - IIRC it is difficult to identify which folder the exe/binary is being run from, hence the use of these absolute paths.
1 个评论
Image Analyst
2012-10-3
That is true. If you just stick stuff in the folder where your exe lives, it won't find it if you use relative paths. That's because what you think is the exe is really a self-extracting archive and the real exe that gets run is in some special secret folder where no one would ever think to look. Just print out ctfroot in the startup code of the app to see where the "real" exe lives.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!