Simple if else function
显示 更早的评论
Hello People,
I'm new into Matlab, and i'm trying to write af simple if-else function. My function af has 3 input variables: - figur=rektangel, trekant or ellipse (to calculate the moment of inertia of said geometry) - b = width - h = height
So for example, if i my input was: [Ix0,Iy0] = inertimoment(rektangle,2,2), it should calculate the moment of inertia of a rectangle of height anf width of 2.
But whenever i run the function, i get an error, that says "undefined function or variable figur"
function [Ix0,Iy0] = inertimoment(figur,b,h)
if strcmp(figur, 'rektangel')
Ix0 = (b*h^3)/12;
Iy0 = (b^3*h)/12;
ifelse strcmp(figur, 'trekant')
Ix0 = b*h^3/36;
Iy0 = b^3*h/36;
else strcmp(figur, 'ellipse')
Ix0 = pi*b*h^3/64;
Iy0 = pi*b^3*h/64;
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!