Matlab results display problem in VB

I have created this function in Matlab:
function [Res] = myDoubInt(param) pc=0;
f1 = @(x)(((log(x) - log(31.1))./ 0.48).^2);
f2 = @(x,y)(2 .* pc .* ((log(x) - log(31.1)) ./ 0.48) .* ((log(y) - log(4.5)) ./ 0.58));
f3 = @(y)(((log(y) - log(4.5)) ./ 0.58) .^ 2);
P = @(x,y)((exp((-0.5 .* (f1(x) - f2(x,y) + f3(y))) ./ (1 - pc .^ 2)))./ (2 .* pi .* x .* y .* 0.48 .* 0.58 .* sqrt(1 - pc .^ 2)));
Q = dblquad(P,10,10000,10,10000);
Res = Q/param; end
If param = 3 the result is 0.0276.The function has no problem.I checked it in Matlab. I used Matlab NE Builder and deploytool so that i can use this function in VB. My code in VB is:
Imports MyDoubleIntegral
Imports MathWorks.MATLAB.NET.Arrays
Imports MathWorks.MATLAB.NET.Utility
Public Class FormMatlab
Dim myDoubInteg = New MyDoubleIntegral.MyDoubleIntegral
Dim tet, REs As Double
Dim f As Object
Public pres As New MWNumericArray(MWArrayComplexity.Real, MWNumericType.Double, 4)
Public pr As New MWNumericArray(MWArrayComplexity.Real, MWNumericType.Double, 4)
Private Sub ButtonMatlab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonMatlab.Click
pr = 3
pres = myDoubInteg.myDoubInt(pr)
LabelMatlab.Text = ToString(pres)
End Sub
End Class
The LabelMatlab.Text should be 0.0276. But when i run it in VB, the labelMatlab.Text is W. i think its a problem in the type conversios.Any help would be apreciated.

回答(1 个)

Friedrich
Friedrich 2011-8-14
Hi,
I would specify the class of ymDoubInteg:
Dim myDoubInteg as You_Class_Name = New MyDoubleIntegral.MyDoubleIntegral
I think the VB ToString methods is not designed for MWARRAYS. The MWARRAY class has his own ToString method:
Try to use this ToString method. If this still not work, cast the MWARRAY to a native data type through the Ctype command:
Dim nativeArray(,) As Double = CType(pres.ToArray(MWArrayComponent.Real), Double(,))

1 个评论

Could you write how the code above will be after you use one of the proposed solutions???

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Deploy to .NET Applications Using MWArray API 的更多信息

标签

提问:

Geo
2011-8-14

Community Treasure Hunt

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

Start Hunting!

Translated by