0
function [ surface_area, volume ] = cube_and_sphere_calculator( geometry,l_r )
if geometry == 1
   surface_area = 6 * l_r^2
   volume = l_r^3 
elseif geometry == 0
   surface_area = 4*pi*l_r^3
   volume = (4/3)*pi*l_r^3
else
   disp('you have to choose a value that is either equal to one if you want to calculate the surface area and the volume of a cube or equal to zero if you want to calculate the surface area and the volume of a sphere')
end
end

If I put semicolons after the formulas, matlab gives only one output variable: ans. This answer is equal to the surface area. I want two output variables, and I want them to be surface_area and volume. Why doesn't it work?

0

1 Answer 1

0

From the matlab documentation Declare function

function [m,s] = stat(x)
n = length(x);
m = sum(x)/n;
s = sqrt(sum((x-m).^2/n));
end

And to call the function.

values = [12.7, 45.4, 98.9, 26.6, 53.1];
[ave,stdev] = stat(values)

So you call the function, the same way you write it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.