How to use while loop and if statements to create an interval
Show older comments
I had a data with multiple same year values. I wanted to use while loop and if statments and create a small intervals that can alter the values so that they can be distinct for plotting. Any pointers?
3 Comments
dpb
on 8 Nov 2019
Why a loop and if statements? Just add a random noise element to each value--how much "jitter" do you want? Or, if you want them offset by regular amounts, just create a set of delta-t values from [-N/2:N/2]*dt and add to each set....this would be simplest if were the same number of duplicated values for each date because could then rearrange by that number and do global addition by automagic unit expansion.
Bisrat Zerihun
on 8 Nov 2019
dpb
on 8 Nov 2019
Yes. What do you consider "a small value"?
What is the format for the x data--are they just doubles holding the year or a datetime variable or what? It's always SO much easier if you'll show us instead of making us guess what we're talking about.
Lastly, still, why a loop and if -- what's wrong with the suggestions made above?
Answers (0)
Categories
Find more on Loops and Conditional Statements 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!