views:

62

answers:

3

I have an array of 20 items long and I would like to make them an output so I can input it into another program.

pos = [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,]

I would like to use this as inputs for another program

function [lowest1, lowest2, highest1, highest2, pos(1), pos(2),... pos(20)]

I tried this and it does not work is there another way to do this?

+2  A: 

I'm a little confused why you'd want to do that. Why would you want 20 outputs when you could just return pos as a single output containing 20 elements?

However, that said, you can use the specially named variable varargout as the last output variable, and assign a cell to it, and the elements of the cell will be expanded into outputs of the function. Here's an example:

function [lowest1, lowest2, highest1, highest2, varargout] = myfun
  % First set lowest1, lowest2, highest1, highest2, and pos here, then:
  varargout = num2cell(pos);
SCFrench
+1  A: 
A: 

Consider using a structure in order to return that many values from a function. Carefully chosen field names make the "return value" self declarative.

function s = sab(a,b)
  s.a = a;
  s.b = b;
zellus