"George Bedford" <email@example.com> wrote in message news:firstname.lastname@example.org... > Hi, > > I'm still an absolute novice at Matlab and I'm trying to build multiple > GUI's for data collection, calibration and processing. I'm currently > having a problem calling a piecewise function to plot using a check box; I > keep receiving the same error message... > "Output argument "y" (and maybe others) not assigned during call to > "C:\.....\BlankSlate.m>pwf"." > ... and I'm not sure why as it does occasionally work.
That suggests you have at least one code path through your function that assigns values to all your output arguments and at least one code path through your function that does not.
> % Apply variables to function > if x < A1 > y = 0; > elseif A1 <= x & x < B1 > y =(-cos(pi*(x-A1)/(B1-A1)))*(1/2)+0.5; > elseif B1 < x & x <= C1 > y = 1; > elseif C1 < x & x <= D1 > y =(-cos(pi*(x-C1)/(D1-C1)+pi))*(1/2)-0.5+1; > elseif D1 < x > y = 0; > end
If none of these conditions are satisfied then y will not be assigned a value. It may look like this covers everything, but this assumes x is not NaN and x is not exactly equal to B1 (assuming C1 > B1.)
One way to detect this would be to assign y the value NaN BEFORE this IF/ELSE section. You could then check if isnan(y) at the end of the function and use KEYBOARD to allow you to investigate why y was not assigned a value.