From: Cem on
Hello,

I have been experiencing the following error when I return multiple arguments from a program that the output arguments of the returned function not assigned during the call to the program. All the output arguments are calculated within the function properly. I believe this is a simple mistake but I cannot see it. Why am I getting this error?

Thank you.

Cem

The Error
-------------------------------------------
tTestN ('CTestasc',2)

??? Output argument "a" (and maybe others) not assigned during call to "C:\tTestN.m (tTestN)".

Error in ==> tTestN at 9
thresh = [];

Error in ==> tTestN at 46
[a,b,c,d,e,f,g]=tTestN(x,y,z,params,fc,fplot,fgsave,fName,ROI_option);

--------------------------------
The Test Program
--------------------------------

function tTestN(pcf,ROI_option)

[a,b,c,d,e,f,g]=TumorN(x,y,z,params,fc,fplot,fgsave,fName,ROI_option);

sprintf('V = %.4f',a/1000)

--------------------------------
THe function that the test program calls
---------------------------------------

function [a,b,c,d,e,f,g] = TumorN(x,y,z,params,fc,fplot,fgsave,fName,ROI_option)

....

if (cVolume ~= 0)
%%% METRICS
%%% Add area measurement to this plot 11/5/09
[geom, iner, cpmo] = polygeom(xedge(ei), yedge(ei));
% Volume
a=cVolume;
% Area
b=geom(1);
% Major Axis Length
major=regionprops(bwlabel(DTpoly),'MajorAxisLength');
b=major.MajorAxisLength*(X1(2,1)-X1(1,1));
% Minor Axis Length
minor=regionprops(bwlabel(DTpoly),'MinorAxisLength');
c=minor.MinorAxisLength*(Y1(1,2)-Y1(1,1));
% Equivalent Diameter=sqrt(4*Area/pi)
d=sqrt(4*b/pi);
% Perimeter Length
c=geom(4);
% Roundness = 4*pi*Area/Perimeter^2
d=4*pi*b/c^2;
end;

....
From: ImageAnalyst on
Well apparently when you call this thing, cVolume is zero, thus it
never gets into the "if" block and "a" never gets assigned, thus it
can't return "a" as it is required to do. You could simply initialize
all return arguments immediately upon entering the function so they'll
always have at least SOMETHING for a value.


From: TideMan on
On Apr 9, 7:59 am, ImageAnalyst <imageanal...(a)mailinator.com> wrote:
> Well apparently when you call this thing, cVolume is zero, thus it
> never gets into the "if" block and "a" never gets assigned, thus it
> can't return "a" as it is required to do.  You could simply initialize
> all return arguments immediately upon entering the function so they'll
> always have at least SOMETHING for a value.

And just some gratuitous advice on coding:
When you have many individual scalars to return, a better practice is
to put them into a structure:
v.a=cVolume;
v.b=geom(1);
etc

Then you call with just one output argument:
v=TumorN(x,y,z,params,fc,fplot,fgsave,fName,ROI_option);
which is easier to maintain if you change the number of output data at
some later date.