09-11-2013 12:24 PM
Hello,
I am trying to write code that will search for a fractional string within an array and convert it from mV to V so it can be properly compared to the other fractional string numbers in the array.
I have an array that outputs x iterations each with a minimum and maximum column including several different types of decimal strings (negative/positive with several decimal places) each ending with either mV and V (example string: -725.543mV).
I then split the array into columns containing the minumum and maximum values of each iteration. I want to compare the minimum values of each iteration and find the most minimum, and do the same thing with the maximum values.
Unfortunatley the way I'm doing it, when I convert from fractional string to number it removes the V or mV unit label but does not convert the number from mV to V. so it compares -725.543mV with -52.334V as -725.543 & -52.334 thus declaring the mV value the most minimum. I need the program to recognize that mV is less than V or search each array for values labeled with mV and move the decimal place so it is in standard V format.
The unit label is actually part of the string and not the display (as you can see in the code I've attached) and I understand this is a little tricky with the way I have to do it. But this is a dumbed down chunk of code I will eventually incorporate into my larger program which reads the values and their units from several different types of oscilloscopes. The Scopes output the values as strings as they appear on the screen and don't differentiate between mV and V unless they are told to output the units which just tags them on the end of the string.
I'm sorry for the large post. SO to sum up I need to search an array to make sure all values have the same units, if they don't I need to convert each value to the proper unit and output the max and min from the resulting array. my code is attached. Thank you for your help.
Solved! Go to Solution.
09-11-2013 12:52 PM
Why don't you search for all string elements with mV and convert them into V? If you need them as mV later, just convert them back.
That is take -725.543mV. Find mV using the search string function. Take the before match output. Turn into a number. Divide by 1000. Turn back into a string. Concatnate a V at the end of it.
09-11-2013 01:18 PM
09-11-2013 02:00 PM
thanks for the help guys. I appreciate it.
09-11-2013 03:21 PM - edited 09-11-2013 03:23 PM
Sorry, Jim, that's not quite right. You forgot to consider significant figures (your third min is not quite right). It does add a bit to the problem, though, because of machine math. You have to work your magic in strings when there are a large number of sig figs (looks like above 8 or so). See attached.
09-12-2013 06:27 AM
@camerond wrote:
Sorry, Jim, that's not quite right. You forgot to consider significant figures (your third min is not quite right). [...]
Good catch, but, really?
😉
Here's how I modified mine to handle precision:
No loops! 😄
09-12-2013 07:07 AM
@jcarmody wrote:
@camerond wrote:
Sorry, Jim, that's not quite right. You forgot to consider significant figures (your third min is not quite right). [...]
Good catch, but, really?
😉
That "Finally!" comes out to -5569492V to me. Holy crap. -5.569492MV! I think there's a problem there.
09-12-2013 07:19 AM - edited 09-12-2013 07:21 AM
09-12-2013 07:49 AM
@crossrulz wrote:
@jcarmody wrote:
@camerond wrote:
Sorry, Jim, that's not quite right. You forgot to consider significant figures (your third min is not quite right). [...]
Good catch, but, really?
😉
That "Finally!" comes out to -5569492V to me. Holy crap. -5.569492MV! I think there's a problem there.
Carp! Stupid negative numbers, shouldn't be allowed. Put a piece of duck tape over the place for that negative sign, that'll fix it.
I'll get back, it's now a matter of principle.
Jim, how does your algorithm do when there are 8 or 9 sig figs, say -56.9492345mV? (Yep, too lazy to draw it in myself.)
Cameron
09-12-2013 07:53 AM