Code covered by the BSD License  

Highlights from
splitvar/splicevar

Be the first to rate this file! 15 Downloads (last 30 days) File Size: 1.87 KB File ID: #31058

splitvar/splicevar

by

 

15 Apr 2011 (Updated )

Splits a 1 x N array into N separate 1 x 1 variables. Improves SAVE time drastically.

| Watch this File

File Information
Description

Saving large (>2 GB) variables using the '-v7.3' flag is terribly slow, especially if the variable is not a simple matrix. If the large variable that is holding you up is a 1-D array, you can use SPLITVAR to break it up into separate variables in the workspace. This could allow you to save the workspace without the dreaded '-v7.3' flag. After reloading the workspace, use SPLICEVAR to build it back into the original variable.

Example:
I have a ~7.5GB 1x22 array of structures.

>> whos
  Name Size Bytes Class
  data 1x22 7580671154 struct

after running SPLITVAR(data) my workspace contains:

>> whos
  Name Size Bytes Class
  data_1 1x1 558955428 struct
  data_10 1x1 182980944 struct
  data_11 1x1 204706714 struct
  data_12 1x1 240433764 struct
  data_13 1x1 242623570 struct
  data_14 1x1 257212788 struct
  data_15 1x1 295351300 struct
  data_16 1x1 277538660 struct
  data_17 1x1 256249924 struct
  data_18 1x1 218259258 struct
  data_19 1x1 255908802 struct
  data_2 1x1 469168036 struct
  data_20 1x1 475334632 struct
  data_21 1x1 469577114 struct
  data_22 1x1 488044446 struct
  data_3 1x1 499091734 struct
  data_4 1x1 455919532 struct
  data_5 1x1 481254514 struct
  data_6 1x1 427976576 struct
  data_7 1x1 445993342 struct
  data_8 1x1 190239504 struct
  data_9 1x1 187854604 struct

To return to the original variable, run:
SPLICEVAR('data').

Saving the original workspace with the '-v7.3' flag for me took a couple of hours. Using SPLITVAR takes less than a second, and using SAVE with no '-v7.3' flag takes a few minutes. Loading the workspace takes about a minute, and running SPLICEVAR to get the original variable back takes less than a second.

It wouldn't take much to modify to allow it to work with more than 1-D arrays!

MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Updates
19 Apr 2011

Updated to a more accurate summary.

Contact us