User-defined configurations for Matlab Compiled Projects - matlab

I am using the Matlab Compiler to compile Matlab code into dlls, which I can run elsewhere. However, my dlls and functions have a lot configuration variables and too many for them all to be an input to the function.
Currently, the user specifies a file path to a .mat file which is loaded within the compiled code for all the configuration settings. A .m file is executed to generate the .mat file. However, when the config settings change, the user must go into the .m file change the necessary settings and re-execute it to generate an updated .mat file.
Obviously, this process is cumbersome and it's easy to forget to re-execute the .m for the config to be updated. A couple things I have considered but seem problematic:
It'd be great if .mat files could be read/editted with text editor, but as far as I can tell this is not possible
Another approach is XML, but I am under the impression Matlab does not have great XML support
Run the .m file to populate the work-space within the compiled dll but this is not possible
So my question is if anyone else has run into this issue before or can think of any other alternative approaches that would be more streamlined than my current approach.
Thanks for reading!

So you could use XML - MATLAB does have support for XML via xmlread and xmlwrite. These functions return/accept a DOM node which you will need to manipulate yourself, though, and that can be a bit fiddly. XML is also not that fun for your users to have to edit or read if they want to change the config.
If you weren't using MATLAB Compiler, you could also use a .m file directly to store config information. But if you're compiling that won't work as the .m file will be encrypted and no longer editable.
I typically use YAML for config files. YAML is a text-based format, so the user will be able to edit them by hand in a text editor and you'll be able to version-control the files; but it's much more human-readable than XML. There are no angle-brackets, it's laid out much more simply, and you can include comments to delimit and explain sections of the config.
MATLAB does not natively support YAML, but there are third-party things that you can download (for example here or here) that work well, are easy to integrate, and are freely licensed. I've also written code myself that I'd be happy to share somehow if you need that.

Related

Distribute a glade file inside an application

Before I start, I know of the existence of GResource, however I'm using gtkmm (C++), and I'm not sure if GResource works with C++. I can't find anything along the lines Glib::GResource, and I've been looking for a while.
Anyway, I'm writing a GUI using Gtkmm, and I want to pack the .glade file which I load within the executable, so that the executable can be run without having to have a file next to it. I'm not sure that I completely understand how GResources work, and I can't find any clear instructions anywhere.
So, using Gtkmm, how would I pack a .glade file inside my executable?
update: I've found this. (Gio::Resource), which sounds hopeful, but no documentation.
I've made some more research and found this tutorial and this documentation. Looks like what you need is Gio::Resource::lookup_data_global. Below is C version of my answer.
When something in glib world lacks documentation, it's time to read documentation for c. In short: with the help of glib-compile-resources and a simple xml file you build a .c file, which can be compiled into your application. After that you can use g_resources_lookup_data (resourceS, it's important) to load data.

Importing source files and folders into IAR Workbench

I have a cup of source files in a certain folder structure in my file system. I want to use this structure for a project in the IAR Workbench. Thinking of Eclipse, that could be so easy! But in the IAR Workbench, the folders will become to "Groups", which are only kind of virtual folders. The Workbench doesn't care about folders.
Is there some easy and fast way to import them?
Up to now I have to add the groups manually each and then add the files to the groups, and that's really annoying!
Is there maybe a tool to generate a proper project file (*.ewp) out of a file/folder structure path?
This would help me a lot!
You should have a look at IAR Project/Add Project Connection command.
Although IAR doesn't seem to have any public documentation on the xml syntax, or at least I couldn't find any, you can find Infineon DAVE (Config.xml) and Freescale PE (ProjectInfo.xml) files if you search around. These can be used as examples to figure out the syntax on how to write your own xml files in one of these interfaces, to allow you to specify where all your c, h, assembly and library files are from where ever they may be in your file system. They also allow you to define preprocessor includes for compiler/assembler, and DAVE allows you to define a path variable, which is also very useful.
See: https://mcuoneclipse.com/2013/11/01/iar-arm-v6-7-comes-with-improved-processor-expert-support/
I have modified a DAVE Config.xml file and found it EXTREMELY useful for managing and migrating even just a handful of project files. For example to upgrade to a new release with all files having a new directory root, you just change a single line in the xml file (defining the new root), and all source files, compiler includes etc are all updated to the new level. No more manually editing the preprocessor includes or replacing all the files in the project. And no more fiddling around with ../../ file system hierarchy navigation stuff, you just specify directly (or indirectly via a path to) where the files are, no more relative from where your project happens to be. VERY NICE.
IAR should consider opening this up (documenting) for general users, as it is very useful for project management and migration. While at it they should also consider generalizing the xml syntax a little bit and allow for definition of IAR group heading names, specifying linker file name, and definitely allowing multiple xml files to be included (connected) (so that subprojects can be easily added or removed without effecting the other subproject definition files) and a few basic things like that.
If they where to do a bang up job on this, they might consider allowing most/all aspects of IAR project configuration that might be required by the subproject, to be defined in these xml files, and then entire (sub)projects could just be plopped down anywhere and be up an running extremely quickly (OK, just let me dream a bit :)
For anyone who happens upon this you may want to check out https://github.com/IARSystems/project-migration-tools. They have a tool for pulling in file trees here.

Adding data files to SBT project

I would like to add a data file or a configuration file along with my application (such as sample.conf). This file should be available to user so that he/she can edit the sample configuration to further customize the application.
How can I add such files to my project such that
This file becomes part of distributable, and
How can I link it in my source documentation, so that its purpose can be doucmented, and
This is file is goes into a special directory (such as conf)
Or is there any such predefined task available.
SBT Native Packager provides support for doing what you want, though you'll have to dig through the docs a bit. The universal packager is probably the best approach for you.
http://www.scala-sbt.org/sbt-native-packager/
I think what you're looking for is the typesafehub/config https://github.com/typesafehub/config project. It uses the HOCON format (Human Optimized Config Object Notation).

MATLAB compiler - preserving source code

I have a question about Matlab compiler, which I am very new to.
I am trying to compile a large Matlab program to a standalone unix application. It has a number of supporting directories (filled with .m files) which run algorithms on input data. One of the key uses of this program is in allowing users to add their own .m files with their own algorithms for the program to run.
I am able to compile the project and run it as a standalone without issue. But the user can no longer access and add supporting files once it had been compiled.
Has anyone ever come across this before and have any suggestions for dealing with it? I understand that the .m files need to be compiled to .exe and such, but I was hoping Matlab might have a workaround for keeping supporting files in their original state.
This behaviour is by design, and you can't get round it - in fact it's not only technically impossible, it's against the license agreement:
5.2.3. Licensee's Application may not provide scripting capability
similar to the capabilities of any of the Programs or provide
functionality or behavior similar to that of the MATLAB command
line.
Imagine if you created an application that simply accepted user input and passed it into the function eval. If you compiled it, you would then be able to essentially give away free copies of the whole of MATLAB to anyone.

Is it possible to hide the source codes of .m files and build project using xcodebuild

I have created a Mac app that can generate iphone ebook app project source codes.
I know I can using xcodebuild to build the project to get the release binary file.
Is it possible to hide the source codes of .m files(maybe store in memory) and build project using xcodebuild?
Welcome any comment
Thanks
Marc
It sounds to me like you are attempting to generate source code for others to use, but then hide it so they cannot see whats been generated. Basically not possible. You could generate obfuscated code which would make it harder to read, but not impossible.
Realistically what you are trying to do is generate template code for others to use. If you don't want them to be able to see it, then you presumably don't want them modifying it. The easiest answer is to simple not do it. Instead, create a compile static framework containing your code and IP, and then only generate templates which makes calls to your framework. Thus your code is protected.
Your question lives on the edge of being programming related, and I'm not exactly sure what problem you're trying to solve.
However, you can create a RAM disk, store your project there and run xcodebuild against that. Just be aware that you're not really protecting the .m files so much as limiting how long they are easily visible.