Error Dialogue box pops up too many times

2 views (last 30 days)
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];
end
if length(start)<length(stop)
start=[start(1)-1 start];
end
out=stop-start;
for ii=1:length(out)
check(start(ii):(stop(ii)-1))=out(ii);
end
for ii=1:length(check)
if check(ii)>20
errordlg('too many consecutive missing points to interpolate check your data set', 'User Malfunction')
end
end

Accepted Answer

Walter Roberson
Walter Roberson on 3 Jul 2012
After the errordlg() call, still inside the "if", add the command
break;

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!