fplot glitch when plotting a square function
Show older comments
Problem description
When plotting a custom function (based on the square() function) using the fplot() command, the plot leaves some gaps where none should be and when panning the plot, these gaps appear at different positions. To see this, just count the gaps (marked red) between 0 and 50 in the plots below - in the first plot, there are 4 gaps and in the second, there are 7 gaps.
I see 3 different sources of error for this:
- A bug in my implementation
- A hardware problem
- A MATLAB problem


MATLAB code:
% Time-conversion factors
seconds_per_minute = 60;
minutes_per_hour = 60;
hours_per_day = 24;
seconds_per_hour = seconds_per_minute*minutes_per_hour;
seconds_per_day = seconds_per_minute*minutes_per_hour*hours_per_day;
% Custom function
photoperiod = 16; % [hours/day]
duty = photoperiod/24*100; % [percent]
day_start = 6;
I_A_max = 150;
I_A = @(t) I_A_max/2*square(((t-day_start)*(2*pi)/24)/seconds_per_hour, duty)+I_A_max/2;
% Make the plot
fplot(@(t) I_A(t*seconds_per_day))
xlabel('time (days)')
ylabel({'Light';'[W/m^2]'})
xlim([0,50])
Can anyone comment on what is causing this behavior?
Accepted Answer
More Answers (0)
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
