1. Tuyển Mod quản lý diễn đàn. Các thành viên xem chi tiết tại đây

Hỏi về Matlab

Chủ đề trong 'Cơ khí - Tự động hoá' bởi Tui_la_ai_new, 26/04/2005.

  1. 0 người đang xem box này (Thành viên: 0, Khách: 0)
  1. Tui_la_ai_new

    Tui_la_ai_new Thành viên quen thuộc

    Tham gia ngày:
    10/04/2002
    Bài viết:
    183
    Đã được thích:
    0
    Hỏi về Matlab

    Xin hỏi một số câu về matlab :
    - Khi lập trình một bài trên phần Gui của matlab, liệu có thể chuyẻn file đó thành exe dể người dùng không phải cài matlab vẫn có thẻ chạy dược nó không ?
    - em muốn làm thực hiện làm tròn số theo nguyên tắc :
    có số 0.1234xy
    nếu x>5 thì thành 0.1235
    nếu x<5 thì thành 0.1234
    nếu x=5 thì nếu y>=5 thi la 0.1235, nếu y<5 thì 0.1234
    em có thử tìm trong matlab thì có thấy mấy lệnh làm tron như round, floor, ceil, fix... nhưng hình như không làm được việc này.

    Rất mong được giúp đỡ
  2. dadelous

    dadelous Thành viên mới

    Tham gia ngày:
    04/04/2004
    Bài viết:
    210
    Đã được thích:
    0
    Cái này tớ nghĩ là đuợc, nhưng rắc rối, đọc thử đoạn này để chuyển nhé:
    http://www.mathworks.com/support/solutions/data/1-12DTGO.html?solution=1-12DTGO
    Subject:
    How can I use compiled functions from MATLAB Builder for Excel in my Microsoft Excel spreadsheet?
    Problem Descriptions
    I would like to call my MATLAB functions from Microsoft Excel using the Microsoft Excel function syntax.
    Solution:
    The following example shows how to call compiled MATLAB Builder for Excel functions from Microsoft Excel. Note that, in order for a function to be called using the Microsoft Excel function syntax (e.g., "=myfunction(input)"), the MATLAB function must return only one, scalar output argument.
    A. The Development Machine
    1. The following three MATLAB functions are provided as examples:
    doubleit.m
    incrementit.m
    powerit.m
    Save these files to your working directory, hereafter referred to as "$work".
    2. Issue the following command at the MATLAB command prompt to select a C++ compiler:

    mbuild -setup
    Subsequent supplied files in this example have been compiled using Microsoft Visual C++ 6.0
    3. Issue the following command at the MATLAB command prompt to launch the graphical user interface for MATLAB Builder for Excel:

    mxltool
    4. In the MATLAB Builder GUI, select "File -> New Project..."
    5. In the New Project Settings GUI, enter "myexcelfunctions" for the Component Name.
    This will automatically fill in the following information:
    - A "myexcelfunctionsclass" class will be created under the "Classes" list.
    - The "Project version" will be set to "1.0"
    - The "Project directory" will be set to "$workmyexcelfunctions"
    In ad***ion to keeping these auto-generated settings, you may wish to select the "Show verbose output" compiler option.
    For your convenience, Step_A5.jpg is attached to show these project settings.
    Select "OK" to save the new project settings.
    6. If prompted, select "Yes" to create the new project directory.
    7. In the MATLAB Builder GUI from Step A4, select "M-files" under the "myexcelfunctionsclass" node.
    8. Click the "Add File" button and add "doubleit.m" from Step A1.
    9. Repeat Step A8 for "incrementit.m" and "powerit.m"
    For your convenience, Step_A7_A9.jpg is attached to show the MATLAB Builder GUI.
    10. In the MATLAB Builder GUI, select "Build -> Excel/COM Object"
    This should generate the following files.
    $workmyexcelfunctionsdistrib\_install.bat
    $workmyexcelfunctionsdistribmyexcelfunctions.bas
    $workmyexcelfunctionsdistribmyexcelfunctions.ctf
    $workmyexcelfunctionsdistribmyexcelfuncgtions_1_0.dll
    11. In the MATLAB Builder GUI, select "Component -> Package Component"
    a. If you have not yet installed the MATLAB Component Runtime onto your deployment machine(s), you will also need to check the "Include MCR" option to include the following file:
    $MATLAB oolboxcompilerdeploywin32MCRInstaller.exe
    where $MATLAB is the MATLAB root directory on your development machine and is given by issuing the following command at the MATLAB command prompt:

    matlabroot
    b. Click the "Create..." button to package the component. This should create the following self-extracting executable:

    myexcelfunctions.exe
    For your convenience, Step_A11.jpg and myexcelfunctions.exe are attached.
    B. The Deployment Machine(s)
    1. Copy myexcelfunctions.exe from Step A11 to the deployment machine(s). It is a good idea to copy the file into a standard place for use with Microsoft Excel. One suggestion would be to place it in the following directory, which would need to be created:
    $OfficeLibraryMATLAB
    where $Office is the Microsoft Office root directory on your deployment machine. For example, for Microsoft Office 2003, $Office might equal:
    D:ApplicationsMSOfficeOFFICE11
    2. Run myexcelfunctions.exe to extract the archive and register myexcelfunctions_1_0.dll. If you have also included MCRInstaller.exe (Step A11a), follow the prompts to install the MATLAB Component Runtime.
    3. Open Microsoft Excel. You should now have a "Book1" spreadsheet open.
    4. In Microsoft Excel, select "Tools -> Macro -> Visual Basic E***or"
    5. In the Microsoft Visual Basic E***or, select "File -> Import File..."
    6. Browse to myexcelfunctions.bas, which was extracted in Step B2, and select "Open".
    In the Project Explorer, you should see "Module1" appear under the "Modules" node beneath "VBAProject (Book1)"
    7. In the Microsoft Visual Basic E***or, select "View -> Microsoft Excel"
    You should now be able to use the doubleit, incrementit, and powerit functions in your Book1 spreadsheet.
    8. If you would like to test this:
    a. Enter the following formula into cell A1:
    =doubleit(2.5)
    b. Enter the following formula into cell A2:
    =incrementit(11,17)
    c. Enter the following formula into cell A3:
    =powerit(7,2)
    You should see the values 5, 28, and 49 in cells A1, A2, and A3, respectively.
    9. If you would like to use the doubleit, incrementit, and powerit functions in all of your Microsoft Excel spreadsheets:
    a. Follow Steps B3 through B7, above.
    b. Without altering the contents of any cells in Book1, select "File -> Save As..."
    c. Change the "Save as type:" option to "Template (*.xlt)"
    d. Browse to your $OfficeXLSTART directory.
    e. Save the file as $OfficeXLSTARTBook.xlt
    Note: You must use the file name "Book.xlt" and your Microsoft Excel''s Macro Security level must be "Medium" or "Low".

Chia sẻ trang này