Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


Ray
Posts:
11
Registered:
7/6/08


Precision of returned values (Builder MWArray)
Posted:
Aug 17, 2008 12:51 AM


Hello,
I a total novice with Matlab. I have a working Matlab application someone else wrote and I'm trying to incorporate it into a C# program using Matlab Builder for .NET. The Matlab code of interest looks something like this:
[latlon time] = Fcn(<arguments>); for k = 1:1:size(latlon,1) fprintf(fid,'%4.15f %4.15f %4.15f\n', latlon(k,:)'); end
When I debug the code running in Matlab itself and place a breakpoint appropriately, I can hover the mouse pointer over latlon and it tells me:
latlon: 1x3 double 39.68 110.24 75.00
When I hover the mouse pointer over time and it tells me:
time: 1x1 double 733583.90
When I print the values to a file using the fprintf, however, there are 15 mostly non0 digits after the decimal point, as I would expect for a type double with an arbitrary fractional part using %4.15f.
So my assumption is that the values I'm shown for the doubles when I hover the mouse pointer over the variables are just the shortened versions for readability, but their real precision is still present and is what I am seeing with the fprintf. Correct so far?
So now for my actual problem... When I create a .NET component for this function and receive it's return value as an MWArray[], the values I appear to be getting are the ones I see when I hover the mouse pointer, that is, they appear to always actually have only 2 digits after the decimal point. Maybe I'm extracting them incorrectly from the MWArray but as near as I can tell the MWArray is in string format and what's there is there as a string only so I'm actually only getting two fractional digits.
In my C# code that calls the function I'm extracting the values from the MWArray as follows:
MWArray[] mwArray = Fcn(2, <arguments>); string locStr = mwArray[0].ToString(); string timeStr = mwArray[1].ToString(); // Split the location values into individual strings. string[] location = locStr.Split(new Char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
double latitude = Convert.ToDouble(location[0]); double longitude = Convert.ToDouble(location[1]); double elevation = Convert.ToDouble(location[2]); double time = Convert.ToDouble(timeStr);
So the bottom line is how to get the values returned with any desired precision rather than always with 2 digits after the decimal point. I don't know whether this is something that must be done on the C# side or the Matlab side. Other than this everything seems to be working fine.
Thanks, Ray Mitchell



