Borrar filtros
Borrar filtros

Can I put words in branching statements?

2 visualizaciones (últimos 30 días)
shreekanteshwara M S
shreekanteshwara M S el 29 de Abr. de 2023
Comentada: Walter Roberson el 29 de Abr. de 2023
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?

Respuestas (1)

VBBV
VBBV el 29 de Abr. de 2023
Editada: VBBV el 29 de Abr. de 2023
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

Categorías

Más información sobre Modeling en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by