I'm playing around with a 'general purpose' plotting routine. I have about 20 different sets of data, each with it's own maximum possible value. The data is added to every 2 weeks.
For instance, one set could range from 0 to 600 whilst another could be 0 to 20.
What I would like to do is find the maximum value in a given set and then round it up to, say, in the case of the 0 to 600 series, the nearest 50/100. So if the largest value in week n is 575 I'd like to round it to 600. in the case of a series from 0 to 20, if the largest value is 15.5 I'd like to round it up to 20.
The rounded value will be used to set the maximum Y value on the chart.
I can think of a method, involving repeatedly diving by 10 to find the magnitude but was wondering if anyone has a more elegant solution.
The language is fairly unimportant, although a 'basic' type would be helpful. The implementation will be in Mobile Basic for iPad.
Thought it may help if you saw a screen shot. Looking at the Platelets plot the largest value is 552 and I would like then 'ymax' to be 600. I also will need to annotate the y axis with appropriate values. The largest Neuts is 11.4 and I would like to sent 'ymax' to 20 on that graph.
Last edited by Nightwalker83; May 18th, 2014 at 06:19 AM.
Reason: Fixed errors!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu. https://get.cryptobrowser.site/30/4111672
Addition to the above code. It should be greater than equal to and lessthan equal to... I got errors if the number was 100, 1000, etc
Ah ok thanks! That is what I had originally but deleted it since you didn't have it in your code.
Last edited by Nightwalker83; May 18th, 2014 at 06:20 AM.
Reason: Fixed grammar!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu. https://get.cryptobrowser.site/30/4111672
Yeah I didnt update the code, But updated in the sandbox thing I was playing with. Also, on the last condition you have <= 1000, should be 10000
Fixed!
Code:
ElseIf number >= 1000 & number <= 10000 Then
Edit:
I originally tried to convert it to VB6 but none of codes for ceil (that I found) worked correctly.
Last edited by Nightwalker83; May 18th, 2014 at 06:29 AM.
Reason: Adding more!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu. https://get.cryptobrowser.site/30/4111672
Private Sub FindScaleMax()
Dim OrderMag As Single
Dim Mag As Single
OrderMag = Int(Log(Largest) / Log(10)) 'Integer part of Log10(Largest).
Mag = 10 ^ OrderMag
ScaleMax = (Int(Largest / Mag) + 1#) * Mag
End Sub
I was a little surprised you didn't get an answer earlier.
This is an example of a class of small problems often used for the performance section of programming job interviews in scientific and engineering companies. They send you to the whiteboard to watch you solve a few such problems. Even if the problem isn't completed, and it generally isn't, attempted solutions using logarithms are "pass" and anything based on iteration is a "fail."
Some say this skews in favor of "conventionality" while the defenders says it evaluates problem solving skills.
I might have come up with the Log solution given enough time. The next interesting problem is using the scale max to create tick marks and labels for the y-axis. When I get stuck no doubt I'll be posting here again.