필터 지우기
필터 지우기

Need help with user made Functions and Sub functions.

조회 수: 2 (최근 30일)
Neil Lallkissoon
Neil Lallkissoon 2017년 3월 16일
답변: GEEVARGHESE TITUS 2017년 3월 17일
Create a function that finds the volume, surface area and perimeter of a rectangular prism of height h, width w and depth d.
It should use separate sub functions to calculate the volume, surface area and the perimeter. The main function should be called and three arguments should be passed as such: function_name(h,w,d).
I have this so far, but I need help. If anybody can help or point me in the right direction, it would be much appreciated. Thank you.

답변 (1개)

GEEVARGHESE TITUS
GEEVARGHESE TITUS 2017년 3월 17일
The assignment operations were not right, and have rectified the code. The invoking format was also not correct, as you require three arguments and the one you provided was a single variable with four values.
function [v,sa,p] = Rectangle(w,h,d)
v = volume(w,h,d);
sa = surface_area(w, h, d);
p = perimeter(w, h, d);
function v = volume(w, h, d)
v = w*h*d;
function sa = surface_area(w, h, d)
sa = 2*(w*d+h*d+h*w);
function p = perimeter(w, h, d)
p = 2*d + 2*w;
%to run the function use [v,sa,p] = Rectangle(1,2,3)

카테고리

Help CenterFile Exchange에서 3-D Volumetric Image Processing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by