.Net c# sdk - MWStructAr​ray.GetFie​ld(string fieldName) Rounding

조회 수: 2 (최근 30일)
bill
bill 2015년 7월 13일
답변: Dasharath Gulvady 2015년 7월 21일
I am trying to read a matlab [48x20 double] matrix via .Net.
In Matlab I see the values as ...
ans =
Columns 1 through 9
0.000800000000000 0.005200000000000 0.005000000000000 0.005000000000000 0.005000000000000 0.005000000000000 0 0 0
0.000800000000000 0.005200000000000 0.005200000000000 0.005150000000000 0.005200000000000 0.005200000000000 0
but after conversion I am seeing this in .Net. Notice .00515 -> .0052
{ Columns 1 through 7
0.0008 0.0052 0.0050 0.0050 0.0050 0.0050 0
0.0008 0.0052 0.0052 0.0052 0.0052 0.0052
My code basically looks like:
var array = ((MWNumericArray)matlabObj.GetField(fieldName));
Am I doing something wrong? Is there a better way to read this in?

답변 (4개)

bill
bill 2015년 7월 17일
Any ideas?

Steven Lord
Steven Lord 2015년 7월 17일
So you generated this application from MATLAB code using MATLAB Compiler SDK? This isn't a separate piece of .NET code that you're invoking from both MATLAB and .NET and seeing different results?
What if you add the command "format longg" to the code from which you generated your application? My guess is that previously in your MATLAB session you changed the display format using that FORMAT call or something similar, and the application generated using MATLAB Compiler SDK is using the default display format (format short.)
Alternately, if you want more specific control, display the values in MATLAB using FPRINTF (the display from the generated application should then be the same as the display in MATLAB.)

bill
bill 2015년 7월 17일
This is a MatLab method compiled into a dll and called from a C# .Net application. When the call comes back from the MatLab code I need to read the values out of the MWArray.
I was under the impression the “Format Long” was just for display but it is something to try.
I guess I could also pass the values back as formatted strings, but I would rather not.

Dasharath Gulvady
Dasharath Gulvady 2015년 7월 21일
As Steven has already mentioned, this may be because of the usage of "format" in MATLAB, which results in higher precision. In your C# application, you may be storing the values in double.

카테고리

Help CenterFile Exchange에서 Deploy to .NET Applications Using MWArray API에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by