How to define a function with multiple names

조회 수: 4 (최근 30일)
Avilash Jain
Avilash Jain 2019년 11월 28일
편집: Masa 2021년 8월 10일
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
Masa
Masa 2021년 8월 10일
편집: Masa 2021년 8월 10일
concept of function handle might be useful in such situations:

댓글을 달려면 로그인하십시오.

답변 (1개)

galaxy
galaxy 2019년 11월 28일
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

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by