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
We can return more than one values from a function by using the method called “call by address”, or “call by reference”. In the invoker function, we will use two variables to store the results, and the function will take pointer type data.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With