Can I put words in branching statements?

조회 수: 1 (최근 30일)
shreekanteshwara M S
shreekanteshwara M S 2023년 4월 29일
댓글: Walter Roberson 2023년 4월 29일
I have a formula which says that F= 1/2*A*Cd*(V+/- Vair)^2
If the air is headwind, The formula is (V+Vair)^2
If the air is tailwind, The formula is (V-Vair)^2
If wind i s not there then the value of Vair is 0.
Can I code this? And also in function?

답변 (1개)

VBBV
VBBV 2023년 4월 29일
편집: VBBV 2023년 4월 29일
Yes, you can use conditional if-else statements like this preferably inside a function
function V = myFunction(V,V_air,air)
if strcmp(air,"headwind")
V = (V+V_air).^2;
elseif strcmp(air,"tailwind")
V = (V-V_air).^2;
else
V_air = 0;
end
end

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by