Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

matlab help !! Q2. Use while loop to get how many full days, full hours, full mi

ID: 3708657 • Letter: M

Question

matlab help !!
Q2. Use while loop to get how many full days, full hours, full minutes and seconds in a given
number of seconds. Display the days, hours, minutes and the remaining seconds. Display only
the units with non-zero values.
Sample outputs:
129667 seconds contains 1 day(s), 12 hr(s), 1 min(s) and 7 sec
275 seconds contains 4 min(s) and 35 sec


Commandselc, clear, format compact, rt, size, lengh, fprintf,array indexing, max, min, sum, mean, norm, linspace, colon operator(). array operations, matrix operations, inv, transpose("). poly, roots, polyval, conv, deconv, close, plot, xlabel, ylabel, grid, legend, input, function, e, load, save, xlsread, xlswrite, if, else, elseif, end, round, r, mod, ceil, floor, fix, for, while, continue, break Topic: while loop, for loop with if, continue and break

Explanation / Answer

t = input('Enter number of seconds');

d = t/24*3600;

H=t/3600;

M=(t - H*60*60 )/60;

S=t - H*60*60 -M*60;

time='';

if d > 0

time = sprintf('%s %d hrs', time, d);

end

if H > 0

time = sprintf('%s %d hrs', time, H);

end

if M > 0

time = sprintf('%s %d min', time, M);

end

if S > 0

time = sprintf('%s %d sec', time, S);

end