Code and decode an entire struct to and from a plain string

10 ビュー (過去 30 日間)
Lars
Lars 2013 年 10 月 5 日
編集済み: Cedric 2013 年 10 月 5 日
Hi,
I need to convert an arbitrary struct to a plain string. I’m going to pass the sting as one single argument to a standalone executable (the exe also built and compiled with MATLAB). Within the exe I’m going to decode the string and rebuild an identical copy of the original stuct. Hence, the string needs to contain all metadata about the struct.
Also: The struct to be passed to the exe is not going to be static. Each time it may contain different fields, cell arrays, etc. But the struct is only going to contain numerical values and strings.
Has anyone done this before and could share the code or give some advice?
Also wondering if there is any limitation on amount and/or size of arguments that could be sent as argument to an exe on the Windows platform?
Should mention that I’m rather new to MATLAB.
// Lars
  5 件のコメント
Lars
Lars 2013 年 10 月 5 日
The exe is going to be installed on a server. It’s going to be run several thousand times a day. It may run simultaneously. It may be called automatically from other apps. It might be called from GUI on workstations. It’s performance critical.
Personally (not being an expert) I think it might get a bit messy (and unnecessary) with all files.
On top of that, the IT department does not want a solution that requires intermediate files to be stored.
So well . . . sending the data as argument through the shell is the best idea I could come up with.
// Lars
dpb
dpb 2013 年 10 月 5 日
The performance of binary mat-file transfer will far outpace ascii string transfer of a serialized structure (orders of magnitude difference).

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

採用された回答

Cedric
Cedric 2013 年 10 月 5 日
編集済み: Cedric 2013 年 10 月 5 日
What you are looking for is "MATLAB struct or object serialization" (on e.g. FEX or Google), but passing a serialized struct as a shell command arg is not robust at all, as mentioned in the comments. Serialization usually generates a significant amount of extra codes/characters, so you'll hit the shell command line limit in no time. Also, it is very likely that you'll have to re-encode strings outputted by the serialization to make them compatible with shell conventions (e.g. for white spaces, quotes, double-quotes).
If you really don't want to build a client-server framework (e.g. if you want to use a CGI-like type of mechanism), and your IT folks don't want too much disk access load, why not storing temporary MAT files on a RAM-drive (using e.g. ImDisk) or equivalent on the system which will host your application?

その他の回答 (1 件)

Image Analyst
Image Analyst 2013 年 10 月 5 日
You can pass variables directly in via the argument list if you make the program a server instead of a standalone executable, but I don't know the details, so call the Mathworks and they can tell you.

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by