How can I plot and reach to this figure ?

4 views (last 30 days)
Khalid Sultan
Khalid Sultan on 5 Aug 2020
Commented: Adam Danz on 6 Aug 2020
I want to know the code that can I get same figure about Biorhythms ?
A) write a MATLAB code that can display Biorhythms for a person given their date of birth and the target date. Your Program should be able to plot the Biorhythms for a suitable spread around the target date (i.e., 30 days).
B) Annotation of the plot and curve with day and date.
C) Create a User‐Defined function to Calculate the total number of days between birthdate and target date. Create your own logic. Do not use any built‐in function (i.e., datenum) to calculate the total number of days
D) Demonstration of features that you have created/coded to add value to graph. · Demonstration that code works correctly using representative samples.

Answers (2)

Star Strider
Star Strider on 5 Aug 2020
Edited: Star Strider on 5 Aug 2020
birthday = datenum(year, month, day);
t = 0:ceil(datenum(now)-birthday);
Physical = sin(2*pi*t/23);
The rest would be calculated similarly.
EDIT — (5 Aug 2020 at 22:34)
You did not previously state that this was an assignment. My initial impression was that you were simply interested in this.
  5 Comments
Khalid Sultan
Khalid Sultan on 5 Aug 2020
function Biorhythms()
from=input('Birth Data [yyyy,mm,dd] :');
to=input('Target Data [yyyy,mm,dd] :');
n=datenum(to)-datenum(from)-1
t=0:1:n+30;
Physical=sin(2*pi()*t/23);
Emotional=sin(2*pi()*t/28);
Intellectual=sin(2*pi()*t/33);
t=t+datenum(from);
t=t(length(t)-61:length(t));
Physical=Physical(length(Physical)-61:length(Physical));
Emotional=Emotional(length(Emotional)-61:length(Emotional));
Intellectual=Intellectual(length(Intellectual)-61:length(Intellectual));
hold on
plot(t,Physical,'blue','LineWidth',2);
plot(t,Emotional,'red','LineWidth',2);
plot(t,Intellectual,'green','LineWidth',2);
datetick('x','dd-mmm')
grid on
legend('Physical','Emotional','Intellectual');
axis([min(t),max(t),-1,1]);
hold off
end
I did what I know .. but it is wrong because i can not know how can plot y axis of -100 to 0 to 100 . Also, the x axis i do not know how will i do it by weeks .
Adam Danz
Adam Danz on 5 Aug 2020
Your assignment states not to use datenum.

Sign in to comment.


Adam Danz
Adam Danz on 5 Aug 2020
I'm not going to do your work for you but I can give you some hints that will get you started. If you are unfamiliar with a function, look it up in the documentation.
1) Define a birthday. You can use datetime(). For example, this is today:
birthday = datetime(2020,08,05);
2) Define a second date which will be used to compute the number of days since the birthday (use datetime again). I'll call this variable endDate.
3) Compute the number of days between birthday and endDate using (fill in the 2 blanks)
daysSinceBirth = days(___ - ___)
4) Create the t variable from the equations you shared. t is a vector of values. Example:
t = linspace(0, daysSinceBirth, 50) where "50" is the number of data points between the min and max.
5) Use sin() to compute the equations you listed in your question. Example (fill in the blank):
y = sin(_____)
6) Create a vector of datetime values that will appear in your x-axis.
dt = birthday + days(t);
7) Use plot() to plot the results: plot(dt,y);
If you get stuck, show us what you tried and I'd be happy to give more hints.
  5 Comments
Adam Danz
Adam Danz on 6 Aug 2020
Good point. I wonder what the instructor means or if that's even an accurate description of the assignment.

Sign in to comment.

Categories

Find more on Birthdays in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!