How to create a user defined function that contain if else function. Can I create a user function from the line e line %user defined function
古いコメントを表示
%menu for user to choose
disp('Convert between Celcious and Fahrenheit');
disp('Choose a number:');
disp('1.Celcious to Fahrenheit');
disp('2.Fahrenheit to Celcious');
%input
choice = input("\nInput:",'s');
while (strcmpi(choice, '1') == 0 && strcmpi(choice, '2') == 0)
disp('Choose number 1 or 2');
choice = input("\nInput: ",'s');
end
%user defined function
if (choice == '1')
cel = input("\nEnter temperature in Celcious to convert to Ferenheit:");
while (cel < 0)
disp('Enter a positive number, please');
cel = input("\nEnter temperature in Celcious to convert to Ferenheit:");
end
if (cel >= 0)
cel2fa = (cel*1.8) + 32;
fprintf('Coverted: %.2f Fahrenheit \n',cel2fa);
end
end
if (choice == '2')
fa = input('\nEnter temperature in Ferenheit to convert to Celcious:');
while (fa < 0)
disp('Enter a positive number, please');
fa = input("\nEnter temperature in Celcious to convert to Ferenheit:");
end
if (fa >= 0)
fa2cel = (fa-32)/1.8;
fprintf('Coverted: %.2f Celcious \n',fa2cel);
end
end
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!