0001 function status = animate_ns_data(seconds,reference,rawfname,plot_res,Max_microv);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if nargin < 1
0013 error('seconds not specified')
0014 end
0015
0016 if nargin < 3
0017 if nargin < 2
0018 reference = 'average';
0019 [fid, rawfname] = get_fid('rb');
0020 fclose(fid);
0021 Max_microv = 100;
0022 plot_res = 40;
0023 else
0024 [fid, rawfname] = get_fid('rb')
0025 fclose(fid);
0026 Max_microv = 100;
0027 plot_res = 40;
0028 end;
0029 end
0030 if nargin < 4
0031 plot_res = 40;
0032 Max_microv = 100;
0033 end
0034 if nargin < 5
0035 plot_res = 40;
0036 end;
0037 if rawfname == []
0038 [fid, rawfname] = get_fid('rb')
0039 fclose(fid);
0040 end;
0041 if reference == []
0042 reference = 'average';
0043 end;
0044 if Max_microv == []
0045 Max_microv = 100;
0046 end;
0047 if plot_res == []
0048 plot_res = 40;
0049 end;
0050
0051 [ref_trialdata, bad_chan] = grab_ns_data(seconds,reference,Max_microv,rawfname);
0052
0053 [xelec,yelec,zelec] = electrodes(size(ref_trialdata,2));
0054 good_chan_mask = ones(1,size(ref_trialdata,2));
0055 ruu = sqrt(xelec(1).^2+yelec(1).^2+zelec(1).^2);
0056 [xs,ys,zs] = polgrid(plot_res,ruu);
0057 if bad_chan ~= []
0058 good_chan_mask(1,bad_chan) = zeros(1,size(bad_chan,2));
0059 end;
0060 good_chan = find(good_chan_mask(1,:));
0061 x = zeros(1,size(good_chan,2));
0062 y = zeros(1,size(good_chan,2));
0063 z = zeros(1,size(good_chan,2));
0064 x = xelec(good_chan);
0065 y = yelec(good_chan);
0066 z = zelec(good_chan);
0067 welec = 1;
0068 icount = 1;
0069 [k,kinv,a,ainv,e] = k_and_e(welec,x,y,z);
0070 for i = 1:size(ref_trialdata,1)
0071 w = ref_trialdata(i,:);
0072 v = zeros(1,size(good_chan,2));
0073 v = w(good_chan);
0074 [p,q,error_check]= mateqs(welec,x,y,z,v,k,kinv,a,ainv,e);
0075 image_3d= interp_3d(welec,x,y,z,xs,ys,zs,p,q);
0076 if ~strcmp(reference,'laplacian')
0077 imagemat= mask(xs,ys,zs,image_3d,120);
0078 else
0079 imagemat = mask(xs,ys,zs,image_3d,108);
0080 end;
0081 if i > 9
0082 outfname = [rawfname '.img_s' int2str(i) ];
0083 else
0084 outfname = [rawfname '.img_s0' int2str(i) ];
0085 end;
0086 outfid = fopen(outfname,'wb');
0087 num_written = fwrite(outfid,imagemat','float');
0088 fclose(outfid);
0089 end;
0090