Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@prog/obj2binary.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % OBJ2BINARY Converts an object to binary representation | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: Converts an object to binary representation. | |
5 % | |
6 % CALL: bin = utils.prog.obj2binary(obj) | |
7 % | |
8 % INPUTS: obj - the object to be converted | |
9 % | |
10 % OUTPUTS: bin - the converted object | |
11 % | |
12 % VERSION: $Id: obj2binary.m,v 1.2 2010/05/18 18:27:35 nicolodi Exp $ | |
13 % | |
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
15 | |
16 function bin = obj2binary(objs) | |
17 | |
18 % get tmp filename | |
19 fname = [tempname '.mat']; | |
20 | |
21 % Convert the objects into a struct if the MATLAB version is less than | |
22 % R2008b because MATLAB have a internal bug with saving user defined | |
23 % objects. | |
24 v = ver('MATLAB'); | |
25 if utils.helper.ver2num(v.Version) < utils.helper.ver2num('7.7') | |
26 warning('off', 'all') | |
27 objs = utils.prog.rstruct(objs); | |
28 warning('on', 'all') | |
29 end | |
30 save(fname, 'objs'); | |
31 | |
32 fd = fopen(fname, 'r'); | |
33 bin = fread(fd, inf, 'int8=>int8'); | |
34 fclose(fd); | |
35 delete(fname); | |
36 end |