Question

In: Mechanical Engineering

How would I go about making a simple code for an analog clock using matlab?

How would I go about making a simple code for an analog clock using matlab?

Solutions

Expert Solution

First of all, choose a Circle with any diameter, say 20 units to draw the outer circle of a clock.drawn. Mark hours from 1 to 12, 30° apart. Read system time by the command. According to the current time of your system, the hours, minutes and seconds hands will be displayed.

Code:

clc;clear;clf;
format shortg;
x=0;y=0;r=10;
hold on;
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
h = plot(xunit,yunit);
r=8; s=[1];
for th = pi/6: pi/6: 2*pi
ytemp = r * cos(th);
xtemp = r * sin(th);  
text(xtemp,ytemp,num2str(s));
s = s+1;
end
while(1)
c = clock;
c = c(1,4:6);
min =c(1,2); sec=c(1,3);
if (c(1,1)>12)  
hr = c(1,1)-12;
else
hr = c(1,1);
end
min1 = ceil(min/12);
theta = (hr*pi)/6 + (min1*pi)/30;
f=figure(1); hold on;
ytemp = 3 * cos(theta); Y = [0 ytemp];
xtemp = 3 * sin(theta); X = [0 xtemp];
p=plot(X,Y);hold on;
theta1 = (min*pi)/30;
ytemp1 = 5 * cos(theta1); Y1 = [0 ytemp1];
xtemp1 = 5 * sin(theta1); X1 = [0 xtemp1];
p1=plot(X1,Y1);
theta2 = (sec*pi)/30;
ytemp2 = 7 * cos(theta2); Y2 = [0 ytemp2];
xtemp2 = 7 * sin(theta2); X2 = [0 xtemp2];
p2=plot(X2,Y2);
pause(1);
delete(p2);
delete(p1);
delete(p);
end

Output:


Related Solutions

C++ Code! This code was written/implemented using the "class format." How would I go about in...
C++ Code! This code was written/implemented using the "class format." How would I go about in converting it to the "struct format?" #include <iostream> #include <iomanip> using namespace std; class ListNode{ public: string course_name; string course_number; string course_room; ListNode* next; ListNode(){ this->next = NULL; } ListNode(string name, string number, string room){ this->course_name = name; this->course_number = number; this->course_room = room; this->next = NULL; } }; class List{ public: ListNode* head; List(){ this->head = NULL; } void insert(ListNode* Node){ if(head==NULL){ head...
I need an original matlab code and gui for a simple double pendulum. This needs to...
I need an original matlab code and gui for a simple double pendulum. This needs to be original and not too complicated. Please provide basic instructions. Thank you!
I want the code for the 2D Ising model using Matlab
I want the code for the 2D Ising model using Matlab
How would you go about writing a MATLAB program to convert a phrase in Pig Latin...
How would you go about writing a MATLAB program to convert a phrase in Pig Latin to English. I have already written a script that converts phrases from English into Pig Latin; however, I am not sure how to reverse the process. Can anyone who know's MATLAB please help me out, thank you? P.S. I know that this is an unambigious task so it doesn't have to work completely well. With the most minor assumptions made, if it could covert...
How would I go about this question using R studio? In a multiple regression, investigate whether...
How would I go about this question using R studio? In a multiple regression, investigate whether the categorical variable "Type" has a statistically significant interaction effect with any of the other covariates, A, B, C and D. Of those interactions that are statistically significant (if any), determine which one has the most impact on the model and add it to your model. Please include general 'formulas' for the commands needed!
Hello, I need the Matlab code of the Fourier Transform without using the Matlab functions fft...
Hello, I need the Matlab code of the Fourier Transform without using the Matlab functions fft and dft. Applied to discrete signals. If you can with an example.Thank you!!
using visual basic how would i go about coding: if checkbox 1 is checked add 10...
using visual basic how would i go about coding: if checkbox 1 is checked add 10 to subtotal if checkbox 2 is checked add 50 to subtotal if checkbox 3 is checked add 100 to subtotal subtotal label is 'lblSubtotal' all 3 boxes are independent. example if checkboxes 1 and 3 are checked 110 would be added to subtotal.
The following code must be written using matlab How to loop through a vector in matlab...
The following code must be written using matlab How to loop through a vector in matlab and assigning a value to every 4th entry. The vector could be of any length. Thanks
How would i go about answering this? Select the range the PH will fall into for...
How would i go about answering this? Select the range the PH will fall into for each .1M solution. a. MnCl3 <1 1 between 1&7 7 between 7&13 13 >13 b. CH3CO2H <1 1 between 1&7 7 between 7&13 13 >13 c. KOH <1 1 between 1&7 7 between 7&13 13 >13 d. NaF <1 1 between 1&7 7 between 7&13 13 >13
how do you demonstrate convultional and clock interleaving matlab?
how do you demonstrate convultional and clock interleaving matlab?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT