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
.matlabroottoolboxdotnetbuilderExamplesVSVersionNETPlotExamplePlotVBAppPlotApp.vbThe program listing is shown here.
The program does the following:
Creates two arrays of double values
Creates a
PlotterobjectCalls the
drawgraphmethod to plotthe equation using the MATLABplotfunctionUses
MWNumericArrayto handle thedata needed by thedrawgraphmethod to plot theequationNote
For information about these data conversion classes, see the MATLABMWArray Class Library Reference, available in the
folder,wherematlabroothelpdotnetbuilderMWArrayAPImatlabrootrepresents your MATLAB installationfolderUses a
try-catchblock to catchand handle any exceptions
The statement
creates an instance of the
Plotterclass,and the statementcalls the method
drawgraph.Build the
PlotAppapplicationusing Visual Studio® .NET.The
PlotVBAppfolder contains a Visual Studio .NETproject file for this example. Open the project in Visual Studio .NETby double-clickingPlotVBApp.vbprojin Windows® Explorer.You can also open it from the desktop by right-clicking PlotVBApp.vbproj > Open OutsideMATLAB.Add a reference to the
MWArraycomponent,which ismatlabroottoolboxdotnetbuilderbinarchitectureframework_versionmwarray.dll.If necessary, add (or fix the location of) a referenceto the
PlotCompcomponent which you built in aprevious step. (The component,PlotComp.dll, isin thePlotExamplePlotCompx86V2.0Debugdistribsubfolderof 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,
cdtothe newPhoneBookExamplesubfolder in your workfolder.
Write the
makephonefunction as youwould any MATLAB function.The following code defines the
makephonefunction: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 PhoneBookCompClass Name phonebookFile to compile makephone.mWrite source code for an application that accesses thecomponent.
The sample application for this example is in
.matlabroottoolboxdotnetbuilderExamplesVSVersionNETPhoneBookExamplePhoneBookVBAppPhoneBookApp.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
MWStructArraytorepresent the example phonebook data.Instantiates the plotter class as
thePhonebookobject,as shown:thePhonebook = new phonebook();Calls the
makephonemethod to createa modified copy of the structure by adding an additional field, asshown:result = thePhonebook.makephone(1, friends);
Build the
PhoneBookVBAppapplicationusing Visual Studio .NET.The
PhoneBookVBAppfolder containsa Visual Studio .NET project file for this example. Open the projectin Visual Studio .NET by double-clickingPhoneBookVBApp.vbprojin Windows Explorer.You can also open it from the desktop by right-clicking PhoneBookVBApp.vbproj > OpenOutside MATLAB.Add a reference to the
MWArraycomponent,which ismatlabroottoolboxdotnetbuilderbinarchitectureframework_versionmwarray.dll.If necessary, add (or fix the location of) a referenceto the
PhoneBookVBCompcomponent which you builtin a previous step. (The component,PhoneBookComp.dll,is in thePhoneBookExamplePhoneBookVBAppx86V2.0Debugdistribsubfolderof your work area.)
Build and run the application in Visual Studio .NET.
The
getphoneprogram should display the output: