matthiasm@8: function hash_add(key, val, fname) matthiasm@8: % HASH_ADD Append key,value pair to end of hashtable stored in a file matthiasm@8: % function hash_add(key, val, filename) matthiasm@8: % matthiasm@8: % See hash_lookup for an example matthiasm@8: matthiasm@8: if ~exist(fname, 'file') matthiasm@8: % new hashtable matthiasm@8: hashtable.key{1} = key; matthiasm@8: hashtable.value{1} = val; matthiasm@8: else matthiasm@8: %hashtable = importdata(fname); matthiasm@8: %hashtable = load(fname, '-mat'); matthiasm@8: load(fname, '-mat'); matthiasm@8: Nentries = length(hashtable.key); matthiasm@8: hashtable.key{Nentries+1} = key; matthiasm@8: hashtable.value{Nentries+1} = val; matthiasm@8: end matthiasm@8: save(fname, 'hashtable', '-mat');