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.

Respuestas (1)

Friedrich
Friedrich el 14 de Ag. de 2011

0 votos

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 comentario

Geo
Geo el 15 de Ag. de 2011
Could you write how the code above will be after you use one of the proposed solutions???

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

Geo
el 14 de Ag. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by