User`s guide
D Utility Library
D-14
Example. This example uses data conversion flags to reshape the output from a
method compiled from a MATLAB function that produces an output vector of
unknown length.
function p = myprimes(n)
if length(n)~=1, error('N must be a scalar'); end
if n < 2, p = zeros(1,0); return, end
p = 1:2:n;
q = length(p);
p(1) = 2;
for k = 3:2:sqrt(n)
if p((k+1)/2)
p(((k*k+1)/2):k:q) = 0;
end
end
p = (p(p>0));
This function produces a row vector of all the prime numbers between 0 and n.
Assume that this function is included in a class named
myclass that is included
in a component named
mycomponent with a version of 1.0. The subroutine takes
an Excel range and a
Double as inputs, and places the generated prime
numbers into the supplied range. The MATLAB function produces a row
vector, although you want the output in column format. It also produces an
unknown number of outputs, and you do not want to truncate any output. To
handle these issues, set the
TransposeOutput flag and the AutoResizeOutput
flag to
True. In previous examples, the Visual Basic CreateObject function
creates the necessary classes. This example uses an explicit type declaration
for the
aClass variable. As with previous examples, this function assumes that
MWInitApplication has been previously called.