function worldClock( time, shift ) %worldClock % Write a function called "worldClock" that creates a 1XN subplot of % analog clocks displaying the time of the cities. Your inputs need to be % a string containing the time in Atlanta, in the standard 12-hour format % (hh:mm), and a 1xN cell array. This 1xN cell array has 1x2 cells for % all of its indices. For example, if your input was 1x2, it could be: % { {'San Francisco', '-3:00'} , {'Austin','-1:00'} } % Where each index in you input cell contains a city and that city's % corresponding time shift from Atlanta's time. % % Here are some instructions and specifications of your plot: % - The perimiter of the clock should be black and consist of 100 evenly % spaced points using linspace() % - Create the circle at the center of the clock by plotting a single % point at (0,0) as a black circle. % - The length of the hour markers is .1 radially inwards from the edge % of the clock. That is, .1 units towards the center of the clock from % the edge. These will all be evenly spaced. % - The hour markers should be black, and correspond to the correct % locations on a normal clock, where 12 o'clock is 90 degrees, and 6 % o'clock is 270 degrees, etc. % - The hour hand should point to the actual hour marker; you do not % need to account for how the hour hand would shift based on the minute % time in a real clock. % - The length of the hour hand should be .6 units. % - The length of the minute hand should be .9 units. % - The hour hand should be blue. % - The minute hand should be red. % - The title of each plot should be the city. % - The axis should be square and turned off. % - The subplot should have the same dimensions as the input cell array, % with each city and time appearing in the same order as they did in % the cell array. % % Hints: % - Keep in mind that the sin() and cos() functions take in radians % - Whether a time is AM/PM will not matter, but your times are still on a % 12 hour scale. As in: if Atlanta's time is 11:00, a shift of +2:00 % will yield a time of 1:00, but it will not matter which of these is AM % or PM. You do not need to keep track of this. Shifts of greater than % 12 hours are possible. % - The rotation matrix could be useful for parts of this problem. numClocks = length(shift); for ndx = 1:numClocks subplot(1, numClocks, ndx); th = linspace(0, 2*pi, 100); plot(cos(th), sin(th), 'k-'); hold on plot(0, 0, 'ko'); hrmark = linspace(0, 2*pi, 13); hrmark = hrmark(end:-1:1); for i = 1:13 plot([(0.9*cos(hrmark(i))), (1*cos(hrmark(i)))], ... [(0.9*sin(hrmark(i))), (1*sin(hrmark(i)))], 'k'); end [atlhr, minutes] = strtok(time, ':'); atlhr = str2num(atlhr) - 1; [hr, ~] = strtok(shift{ndx}{2}, ':'); hrshift = hr(1); hr = str2num(hr(2:end)); if hr >= 12 hr = mod(hr, 12); end if hrshift == '+' hr = atlhr - hr; else hr = atlhr + hr; end ok = true; while ok if hr > hrmark(1) hr = hr - 12; elseif hr <= 0 hr = hr + 12; else ok = false; end end plot([0, (0.6*cos(hrmark(hr)))], ... [0, (0.6*sin(hrmark(hr)))], 'b'); minmark = linspace(0, 2*pi, 61); minutes = str2num(minutes(2:end))+30; plot([0, 0.9*cos(minmark(minutes))], ... [0, 0.9*sin(minmark(minutes))], 'r'); title(shift{ndx}{1}); axis square axis off end end