Plots Visual Basic

Plots Visual Basic
  1. Plots End Visual Basic
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:

  1. Review the sample application for this example in matlabroottoolboxdotnetbuilderExamplesVSVersionNETPlotExamplePlotVBAppPlotApp.vb.

    The program listing is shown here.

    The program does the following:

    • Creates two arrays of double values

    • Creates a Plotter object

    • Calls the drawgraph method to plotthe equation using the MATLAB plot function

    • Uses MWNumericArray to handle thedata needed by the drawgraph method to plot theequation

      Note

      For information about these data conversion classes, see the MATLABMWArray Class Library Reference, available in the matlabroothelpdotnetbuilderMWArrayAPI folder,where matlabroot represents your MATLAB installationfolder

    • Uses a try-catch block to catchand handle any exceptions

    The statement

    creates an instance of the Plotter class,and the statement

    calls the method drawgraph.

  2. Build the PlotApp applicationusing Visual Studio® .NET.

    1. The PlotVBApp folder contains a Visual Studio .NETproject file for this example. Open the project in Visual Studio .NETby double-clicking PlotVBApp.vbproj in Windows® Explorer.You can also open it from the desktop by right-clicking PlotVBApp.vbproj > Open OutsideMATLAB.

    2. Add a reference to the MWArray component,which is matlabroottoolboxdotnetbuilderbinarchitectureframework_versionmwarray.dll.

    3. If necessary, add (or fix the location of) a referenceto the PlotComp component which you built in aprevious step. (The component, PlotComp.dll, isin the PlotExamplePlotCompx86V2.0Debugdistrib subfolderof your work area.)

  3. 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.

Visual

Note

For complete reference information about the MWArray classhierarchy, see the MWArray API documentation.

Visual

Procedure

Plots End Visual Basic

  1. If you have not already done so, copy the files for thisexample as follows:

    1. Copy the following folder that ships with MATLAB toyour work folder:

    2. At the MATLAB command prompt, cd tothe new PhoneBookExample subfolder in your workfolder.

  2. 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.

  3. From the MATLAB apps gallery, open the LibraryCompiler app.

  4. 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 NamePhoneBookComp
    Class Namephonebook
    File to compilemakephone.m
  5. Write source code for an application that accesses thecomponent.

    The sample application for this example is in matlabroottoolboxdotnetbuilderExamplesVSVersionNETPhoneBookExamplePhoneBookVBAppPhoneBookApp.vb.

    The 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);

  6. Build thePhoneBookVBApp applicationusing Visual Studio .NET.

    1. The PhoneBookVBApp folder containsa Visual Studio .NET project file for this example. Open the projectin Visual Studio .NET by double-clicking PhoneBookVBApp.vbproj in Windows Explorer.You can also open it from the desktop by right-clicking PhoneBookVBApp.vbproj > OpenOutside MATLAB.

    2. Add a reference to the MWArray component,which is matlabroottoolboxdotnetbuilderbinarchitectureframework_versionmwarray.dll.

    3. 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 the PhoneBookExamplePhoneBookVBAppx86V2.0Debugdistrib subfolderof your work area.)

  7. Build and run the application in Visual Studio .NET.

    The getphone program should display the output: