# Thread: Matlab function with vector inputs and matrix outputs

1. ## Matlab function with vector inputs and matrix outputs

Hi all,

I need to write a matlab function file (in editor) for a cylinder.
The input values will be vectors containing the heights and radii of various different cylinders, and the outputs will be surface area, cross sectional area, and volume in a matrix.

I know how to write a function with singular inputs, but i can't get vector inputs to work.

Any help would be appreciated.

2. Originally Posted by deragon999
Hi all,

I need to write a matlab function file (in editor) for a cylinder.
The input values will be vectors containing the heights and radii of various different cylinders, and the outputs will be surface area, cross sectional area, and volume in a matrix.

I know how to write a function with singular inputs, but i can't get vector inputs to work.

Any help would be appreciated.

CB

3. I want it like this:

So that the following can be typed into matlab command:

which will result in an output of:

surfacearea1 area1 volume1
surfacearea2 area2 volume2
surfacearea3 area3 volume3
etc etc etc

If the output matrix has to be aligned a different way(my examples rows as columns instead) then thats fine, i just need to be able to get an output that gives all 3 areas/volumes from the given dimensions.

Thanks for taking some time to look at this though.

4. Originally Posted by deragon999
I want it like this:

So that the following can be typed into matlab command:

which will result in an output of:

surfacearea1 area1 volume1
surfacearea2 area2 volume2
surfacearea3 area3 volume3
etc etc etc

If the output matrix has to be aligned a different way(my examples rows as columns instead) then thats fine, i just need to be able to get an output that gives all 3 areas/volumes from the given dimensions.

Thanks for taking some time to look at this though.
Code:
function rv=cylinder(height, radius)

% first make sure we have column vectors

sz1=size(height);
if sz1(1) ~= 1
ht=height';
else
ht=height;
end

if sz1(1) ~= 1
rv=[sarea;xarea;volume]';