It turns out my old code is not as messy as I thought. There are lots of comments, and it is relatively logically structured. I have decided to just modify the old code.
setappdata(STVFig,'dataset.isosurf.M',[]);It doesn't like the fields (ie "isosurf" and "M"). It is quite happy if I just do this:
setappdata(STVFig, 'dataset',[]);
dataset.isosurf.M = [];
dataset.isosurf.M =1;but that doesn't seem to be working either.
dataset.isosurf.O = 2;
setappdata(STVFig,'dataset',dataset);