MATLAB - multiple return values from a function?

Nick picture Nick · Nov 15, 2010 · Viewed 100.8k times · Source

I'm writing 2 functions in matlab, an initialize function and a function to insert items into an array treating it like a doubly-linked list. However, my initialize function only returns "ans =" and the initialized array. How can I have it also set values of my other variables? Here's my code:

function [ array, listp, freep ] = initialize( size )
    array = zeros(size, 3);
    listp = 0;
    freep = 1;
end

Answer

Mikhail picture Mikhail · Nov 15, 2010

Matlab allows you to return multiple values as well as receive them inline.

When you call it, receive individual variables inline:

[array, listp, freep] = initialize(size)