How to display format time in sprintf or similar?
22 ビュー (過去 30 日間)
古いコメントを表示
% script determines the optimum cooking time for perfectly roasted pork.
% yummmy!
%input weight of roast in kg
%output time to cook roast.
clear, clc
weight = input('please enter weight of roast(kg): ');
finisht = input('please enter finish time (in decimal hours): ');
duration = 45*(weight/0.5); %45minutes per 0.5kg
timetopreheat = 10/60; %10 minutes
timeattwotendeg = 15/60; %15 minutes
timeatonefiftydeg = duration/60;
whenpreheatoven = finisht - timeatonefiftydeg - timeattwotendeg - timetopreheat;
whenputroastin = finisht - timeatonefiftydeg - timeattwotendeg;
whenturndowntoonefiftydeg = finisht - timeatonefiftydeg;
whenremoveoven = finisht;
disp(' ')
disp('Preheat oven to 210²C')
disp('Place roast on roasting dish and put in oven')
disp('Roast for 15minutes @ 210²C then')
time = sprintf('Reduce temperture to 150²C and cook for %.0f minutes', duration);
disp(time)
disp(' ')
disp('Note: the following instruction times are in in decimal hours.')
disp(' ')
time1 = sprintf('You should preheat the oven to 210²C at %f: ', whenpreheatoven);
disp(time1)
time2 = sprintf('You should put the roast in oven at %f: ', whenputroastin);
disp(time2)
time2 = sprintf('You should turn down oven to 150²C at %f: ', whenturndowntoonefiftydeg);
disp(time2)
disp(' ')
disp('OR')
disp(' ')
% convert the times above into easily readable times.
% I'd rather this times were displayed in the lines above, but I get an error message I dont not know how to overcome.
whenpreheatovenA= hours(whenpreheatoven);
whenpreheatovenA.Format = 'hh:mm';
disp(whenpreheatovenA)
whenputroastinA = hours(whenputroastin);
whenputroastinA.Format = 'hh:mm';
disp(whenputroastinA)
whenturndowntoonefiftydegA = hours(whenturndowntoonefiftydeg);
whenturndowntoonefiftydegA.Format = 'hh:mm';
disp(whenturndowntoonefiftydegA)
0 件のコメント
回答 (1 件)
Sulaymon Eshkabilov
2020 年 9 月 8 日
Hi,
instead of disp and sprintf, fprintf can be used more efficiently, e.g.:
fprintf('Reduce temperture to 150²C and cook for %.0f minutes \n', duration);
disp(' ')
disp('Note: the following instruction times are in in decimal hours.')
disp(' ')
fprintf('You should preheat the oven to 210²C at %f: \n', whenpreheatoven);
fprintf('You should put the roast in oven at %f: \n', whenputroastin);
fprintf('You should turn down oven to 150²C at %f: \n', whenturndowntoonefiftydeg);
参考
カテゴリ
Help Center および File Exchange で Calendar についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!