When you plot a line that wraps, and do not want the sawtooth shape to show up in the plot, you can either draw all separate lines, or you can insert NaN's between the segments. The plot command does not draw a line between NaN's.
This assignment is to create a function that wraps a vector, and inserts NaN's where it wraps.
The modulo of the wrapping range is explicitly entered into the function.
For example, if we wrap a vector [1:20] at 3, this will result in [1 2 nan 0 1 2 nan 0 1 2 nan 0 1 2 nan 0 1 2 nan 0 1 2 nan 0 1 2].
As (almost) always, regexp and eval are not appreciated.
Solution Stats
Problem Comments
3 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers21
Suggested Problems
-
Number of 1s in a binary string
10966 Solvers
-
Piecewise linear interpolation
614 Solvers
-
60 Solvers
-
74 Solvers
-
Max Change in Consecutive Elements
178 Solvers
More from this Author31
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
a couple of issues: 1) I believe you are missing the input 'm' to wrapnan in your testsuite; 2) some numerical precision issues arise in the last test (e.g. rem(.8,.5)-.3 returns ~.5e-17), perhaps you could just round to two decimals the output of wrapnan so that we do not have to?
I fixed it. Thank you for reminding me. You might submit a shorter solution now.
I am still determining what's happening in the third case. A NaN is inserted before 1.40 but not before 1.50, which is a multiple of 0.50? The difference between 1.80 and 1.40 is 0.4, not 0.5 either...so what's going on? Every time we crossed a multiple of a factor m going up or down, a NaN should have been inserted. Imho, the problem is unclear about what should be done or the 3rd test is wrong. Maybe a sketch would help.