How to define a function with multiple names

5 visualizaciones (últimos 30 días)
Avilash Jain
Avilash Jain el 28 de Nov. de 2019
Editada: Masa el 10 de Ag. de 2021
Say, I want to wtrie a function that converts from foot to meter, and another function that converts from feet/day to meter/day, Since the formula wil be same for both the functions, instead of having same formaula in two function definition, is it possible to add multiple function names while defining the function?
  1 comentario
Masa
Masa el 10 de Ag. de 2021
Editada: Masa el 10 de Ag. de 2021
concept of function handle might be useful in such situations:

Iniciar sesión para comentar.

Respuestas (1)

galaxy
galaxy el 28 de Nov. de 2019
As I know, you can't do it.
You should create only 1 function and switch converting such as same following
function out_val = Convert(in_val, conv_type)
if (strcmp(conv_type, 'feed/day'))
% out_val = convert operation
elseif(strcmp(conv_type, 'meter/day'))
% out_val = convert operation
else
% out_val = convert operation
end
end

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by