Simple if else function
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Data Type Identification finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!