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일

0 개 추천

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

Geo
Geo 2011년 8월 15일
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