Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab object takes a large space in a .mat file

Tags:

matlab

I have an object from some class I wrote in Matlab. When I use "whos" command to determine its size, it is roughly 720,000 Bytes. When I save it in a .mat file it take roughly 75MB. What is going on?

Is there an efficient way of saving and loading an object in Matlab?

EDIT: Here is a list of the properties and their size

            CT_COL: 2
            p: 5
            d: 10
            n: 37
            N: 20
          idx: [20x1 double]
           Am: [4-D double]
            X: [4-D double]
            y: [37x1 double]
        KGram: [20x20 double]
       reWave: []
          rpw: 2
         grps: [1x37 double]
        exIDX: [1 4 5 6 13]
          nCV: 100
        prIDX: [100x6 double]
        trIDX: [100x26 double]
            U: [5x100 double]
            V: [10x100 double]
            B: [20x100 double]
         Yhat: [37x100 double]
          Lam: [100x1 double]
    peakRatio: [37x1 double]

Both Am and X are 20x10x5x37 arrays (of double)

By the way, the property "reWave" used to hold the handle of a method of another object. I thought that might not be a good idea (and might be causing this), so I have removed any mention of it from the class definition. But it seems to somehow appear in the set of properties. (Even after I have issued "clear classes".)

EDIT2: I am using the command save('uvXbMod1.mat','ob') to save just the object. Here comes the puzzling: When I use the command whos -file uvXbMod1.mat to see what is saved inside the file, it shows

Name      Size             Bytes   Class        Attributes

ob        1x1              680512  uvXbModel   

(This is for another instance, not the one mentioned above.) What else is put in the .mat file that makes it that big?

EDIT3: OK... The problem seemed to be two inline function handles I stored in two protected properties. Just these two, @(X) median(abs(X),2) and @median . The handles themselves were just a few bytes in size, and I assumed that since they are inline functions, they should just be stored along with their one-line definitions as text (?). But apparently that does not happen, it causes a huge amount of other things to be stored along (which doesn't seem that strange after the fact ...)

like image 426
passerby51 Avatar asked Apr 25 '13 03:04

passerby51


1 Answers

Here is the issue that I have found with my code: The problem was two inline anonymous function handles I stored in two protected properties. Just these two, @(X) median(abs(X),2) and @median.

The handles themselves were just a few bytes in size, and I assumed that since they are inline anonymous functions, they should just be stored along with their one-line definitions as text. But apparently that does not happen, and it causes a huge amount of other things to be stored along.

like image 133
passerby51 Avatar answered Oct 29 '22 16:10

passerby51