Plots Visual Basic
Integrating a Simple MATLAB Function
Quadratic Functions Graph Plotter. This is a program that can plot graphs for quadratic functions. The formula of a quadratic equation is f (x)= ax 2 +bx+c, where a, b and c are constant. This program employs a picture box as the plot area and three text boxes to obtain the values of the coefficients a, b, c of the quadratic equation from the users. Code Advisor for Visual Basic 6. This application plugs-in to Visual Basic 6.0 to analyze your code and suggest possible improvements. If you are programming in Visual Basic 6.0 and planning to move to Visual Basic.NET, then the Visual Basic 6.0 Code Advisor is for you.The Code Advisor for Visual Basic 6 is an add-in used to review your code to ensure that it meets predetermined coding standards.
The purpose of these examples is to highlight mainsteps required for integrating a MATLAB® function.
Simple Plot
To create the component for this example, see Integrating a Simple MATLAB Function. Then create a Visual Basic® applicationas follows:
Review the sample application for this example in
.matlabroot
toolboxdotnetbuilderExamplesVSVersion
NETPlotExamplePlotVBAppPlotApp.vbThe program listing is shown here.
The program does the following:
Creates two arrays of double values
Creates a
Plotter
objectCalls the
drawgraph
method to plotthe equation using the MATLABplot
functionUses
MWNumericArray
to handle thedata needed by thedrawgraph
method to plot theequationNote
For information about these data conversion classes, see the MATLABMWArray Class Library Reference, available in the
folder,wherematlabroot
helpdotnetbuilderMWArrayAPImatlabroot
represents your MATLAB installationfolderUses a
try-catch
block to catchand handle any exceptions
The statement
creates an instance of the
Plotter
class,and the statementcalls the method
drawgraph
.Build the
PlotApp
applicationusing Visual Studio® .NET.The
PlotVBApp
folder contains a Visual Studio .NETproject file for this example. Open the project in Visual Studio .NETby double-clickingPlotVBApp.vbproj
in Windows® Explorer.You can also open it from the desktop by right-clicking PlotVBApp.vbproj > Open OutsideMATLAB.Add a reference to the
MWArray
component,which ismatlabroot
toolboxdotnetbuilderbinarchitecture
framework_version
mwarray.dll.If necessary, add (or fix the location of) a referenceto the
PlotComp
component which you built in aprevious step. (The component,PlotComp.dll
, isin thePlotExamplePlotCompx86V2.0Debugdistrib
subfolderof your work area.)
Build and run the application in Visual Studio .NET.
Phone Book
makephone Function
The makephone
function takes a structurearray as an input, modifies it, and supplies the modified array asan output.
Note
For complete reference information about the MWArray
classhierarchy, see the MWArray API documentation.
Procedure
Plots End Visual Basic
If you have not already done so, copy the files for thisexample as follows:
Copy the following folder that ships with MATLAB toyour work folder:
At the MATLAB command prompt,
cd
tothe newPhoneBookExample
subfolder in your workfolder.
Write the
makephone
function as youwould any MATLAB function.The following code defines the
makephone
function:This code is already in your work folder in
PhoneBookExamplePhoneBookCompmakephone.m
.From the MATLAB apps gallery, open the LibraryCompiler app.
Build the .NET component. See the instructions in Generate a .NET Assembly and Build a .NET Application for more details. Use the following information:
Project Name PhoneBookComp
Class Name phonebook
File to compile makephone.m
Write source code for an application that accesses thecomponent.
The sample application for this example is in
.matlabroot
toolboxdotnetbuilderExamplesVSVersion
NETPhoneBookExamplePhoneBookVBAppPhoneBookApp.vbThe program defines a structure array containing names and phonenumbers, modifies it using a MATLAB function, and displays theresulting structure array.
The program listing is shown here.
The program does the following:
Creates a structure array, using
MWStructArray
torepresent the example phonebook data.Instantiates the plotter class as
thePhonebook
object,as shown:thePhonebook = new phonebook();
Calls the
makephone
method to createa modified copy of the structure by adding an additional field, asshown:result = thePhonebook.makephone(1, friends);
Build the
PhoneBookVBApp
applicationusing Visual Studio .NET.The
PhoneBookVBApp
folder containsa Visual Studio .NET project file for this example. Open the projectin Visual Studio .NET by double-clickingPhoneBookVBApp.vbproj
in Windows Explorer.You can also open it from the desktop by right-clicking PhoneBookVBApp.vbproj > OpenOutside MATLAB.Add a reference to the
MWArray
component,which ismatlabroot
toolboxdotnetbuilderbinarchitecture
framework_version
mwarray.dll.If necessary, add (or fix the location of) a referenceto the
PhoneBookVBComp
component which you builtin a previous step. (The component,PhoneBookComp.dll
,is in thePhoneBookExamplePhoneBookVBAppx86V2.0Debugdistrib
subfolderof your work area.)
Build and run the application in Visual Studio .NET.
The
getphone
program should display the output: