I have a script with a simple check to see if there are too many consecutive Nan's. It uses a cubic spline interpolation to fix NaN's but I don't want it to interpolate if there more then 20 consecutive Nan's in the program. I have an error dialogue box that comes up in a loop, but if there is more than one spot with more than 20 consecutive NaN's the error box comes up multiple times. i only want the dialogue box to open once if there is 1 or more places with 20 consecutive NaN's. Here is what I did, is there a better solution to creating the error box?
if true % code
check = flow;check(~isnan(check))=0;check(isnan(check))=1;c=diff(check);start=find(c==1)+1;stop=find(c==-1)+1;if length(stop)<length(start) stop=[stop start(end)+1];endif length(start)<length(stop) start=[start(1)-1 start];endout=stop-start;for ii=1:length(out)check(start(ii):(stop(ii)-1))=out(ii);endfor ii=1:length(check) if check(ii)>20 errordlg('too many consecutive missing points to interpolate check your data set', 'User Malfunction') endend
Best Answer