<strike id="ybkjs"><bdo id="ybkjs"></bdo></strike>

    <strike id="ybkjs"><blockquote id="ybkjs"></blockquote></strike>
    <label id="ybkjs"><sub id="ybkjs"><rt id="ybkjs"></rt></sub></label>
  1. <label id="ybkjs"></label>
  2. <label id="ybkjs"></label>

    <label id="ybkjs"></label>
    <legend id="ybkjs"></legend>
    訊技光電公司首頁 最新公告:2025年訊技課程安排發布啦! 智能光學設計大賽官網|黌論教育網校|English|蘇州訊技|深圳訊技|聯系我們|全站搜索
    欄目列表
    FRED
    VirtualLab
    Macleod
    GLAD
    OCAD
    Optiwave
    LASCAD
    Litestar 4D
    TechwizD和TX液晶顯示軟件
    JCMSuite
    EastWave
    PanDao
    光學實驗教具
    最新發布

    天文光干涉儀

    雙折射晶體偏振干涉效應

    顏色分析

    FRED應用:顏色分析

    FRED應用:數字化極坐標數據

    FRED應用:波片模擬

    FRED應用:MTF的計算

    FRED應用:LED手電筒模擬

    FRED應用:模擬沃拉斯頓棱鏡

    FRED應用:準直透鏡模擬與優

    當前位置: 主頁 > 服務項目 > 案例分析 > FRED >
    FRED如何調用Matlab
    時間:2016-01-18 21:23來源:訊技光電作者: 技術部點擊:打印
    簡介:FRED作為COM組件可以實現與Excel、VB、Matlab等調用來完成龐大的計算任務或畫圖,本文的目的是通過運行一個案例來實現與Matlab的相互調用,在此我們需要借助腳本來完成,此腳本為視為通用型腳本。
     
    配置:在執行調用之前,我們需要在Matlab命令行窗口輸入如下命令:
    enableservice('AutomationServer', true)
    enableservice('AutomationServer')
    結果輸出為1,這種操作方式保證了當前的Matlab實體可以用于通信。
     
    在winwrp界面,為增加和使用Matlab類型的目錄庫,我們需要如下步驟:
    1. 在FRED腳本編輯界面找到參考.
    2. 找到Matlab Automation Server Type Library
    3. 將名字改為MLAPP
     
     
    在Matlab里面有兩種常用的數據發送選項PutWorkspaceData 及PutFullMatrix,PutWorkspaceData適用于存儲一般的數據在工作區,并賦予其為變量,PutFullMatrix試用于復數數據。
     
    圖 編輯/參考
     
     
    現在將腳本代碼公布如下,此腳本執行如下幾個步驟:
    1. 創建Matlab服務器。
    2. 移動探測面對于前一聚焦面的位置。
    3. 在探測面追跡光線
    4. 在探測面計算照度
    5. 使用PutWorkspaceData發送照度數據到Matlab
    6. 使用PutFullMatrix發送標量場數據到Matlab中
    7. 用Matlab畫出照度數據
    8. 在Matlab計算照度平均值
    9. 返回數據到FRED中
     
    代碼分享:
     
    Option Explicit
     
    Sub Main
     
        Dim ana As T_ANALYSIS
        Dim move As T_OPERATION
        Dim Matlab As MLApp.MLApp
        Dim detNode As Long, detSurfNode As Long, anaSurfNode As Long
        Dim raysUsed As Long, nXpx As Long, nYpx As Long
        Dim irrad() As Double, imagData() As Double, reals() As Double, imags() As Double
        Dim z As Double, xMin As Double, xMax As Double, yMin As Double, yMax As Double
        Dim meanVal As Variant
     
        Set Matlab = CreateObject("Matlab.Application")
     
        ClearOutputWindow
     
        'Find the node numbers for the entities being used.
        detNode = FindFullName("Geometry.Screen")
        detSurfNode  = FindFullName("Geometry.Screen.Surf 1")
        anaSurfNode = FindFullName("Analysis Surface(s).Analysis 1")
     
        'Load the properties of the analysis surface being used.
        LoadAnalysis anaSurfNode, ana
     
        'Move the detector custom element to the desired z position.
        z = 50
        GetOperation detNode,1,move
        move.Type = "Shift"
        move.val3 = z
        SetOperation detNode,1,move
        Print "New screen position, z = " &z
     
        'Update the model and trace rays.
        EnableTextPrinting (False)
            Update
            DeleteRays
            TraceCreateDraw
        EnableTextPrinting (True)
     
        'Calculate the irradiance for rays on the detector surface.
        raysUsed  = Irradiance( detSurfNode, -1, ana, irrad )
        Print raysUsed & " rays were included in the irradiance calculation.
     
        'When using real number data to send to MATLAB, it is simplest to use PutWorkspaceData.
        Matlab.PutWorkspaceData("irradiance_pwd","base",irrad)
     
        'PutFullMatrix is more useful when actually having complex data such as with
        'scalar wavefield, for example. Note that the scalarfield array in MATLAB
        'is a complex valued array.
        raysUsed = ScalarField ( detSurfNode, -1, ana, reals, imags )
        Matlab.PutFullMatrix("scalarfield","base", reals, imags )
        Print raysUsed & " rays were included in the scalar field calculation."
     
        'Calculate plot characteristics from the T_ANALYSIS structure.  This information is used
        'to customize the plot figure.
        xMin = ana.posX+ana.AcellX*(ana.Amin-0.5)
        xMax = ana.posX+ana.AcellX*(ana.Amax+0.5)
        yMin = ana.posY+ana.BcellY*(ana.Bmin-0.5)
        yMax = ana.posY+ana.BcellY*(ana.Bmax+0.5)
        nXpx = ana.Amax-ana.Amin+1
        nYpx = ana.Bmax-ana.Bmin+1
     
        'Plot the data in Matlab with some parameters calculated from the T_ANALYSIS
        'structure.  Set the axes labels, title, colorbar and plot view.
        Matlab.Execute( "figure; surf(linspace("&xMin &","&xMax &","&nXpx &"),linspace("& yMin &"," & yMax & "," & nYpx & "),irradiance_pwd, 'EdgeColor', 'None');" )
        Matlab.Execute( "xlabel('X Position (" & GetUnits() & ")')" ) : Matlab.Execute( "ylabel('Y Position (" & GetUnits() & ")')" ) : Matlab.Execute( "zLabel( 'Irradiance' )" )
        Matlab.Execute( "title('Detector Irradiance')" )
        Matlab.Execute( "colorbar" )
        Matlab.Execute( "view(2)" )
        Print ""
        Print "Matlab figure plotted..."
     
        'Have Matlab calculate and return the mean value.
        Matlab.Execute( "irrad = mean(mean(irradiance_pwd));" )
        Matlab.GetWorkspaceData( "irrad", "base", meanVal )
        Print "The mean irradiance value calculated by Matlab is: " & meanVal
     
        'Release resources
        Set Matlab = Nothing
     
    End Sub
     
    最后在Matlab畫圖如下:
     
    并在工作區保存了數據:
     

     
    并返回平均值:
     
    與FRED中計算的照度圖對比:
       
    例:
     
    此例系統數據,可按照此數據建立模型
     
    系統數據
     
     
    光源數據:
    Type: Laser Beam(Gaussian 00 mode)
    Beam size: 5;
    Grid size: 12;
    Sample pts: 100;
    相干光;
    波長0.5876微米,
    距離原點沿著Z軸負方向25mm。
     
    對于執行代碼,如果想保存圖片,請在開始之前一定要執行如下代碼:
    enableservice('AutomationServer', true)
    enableservice('AutomationServer')
    關于我們
    公司介紹
    專家團隊
    人才招聘
    訊技風采
    員工專區
    服務項目
    產品銷售
    課程中心
    專業書籍
    項目開發
    技術咨詢
    聯系方式
    地址:上海市嘉定區南翔銀翔路819號中暨大廈18樓1805室    郵編:201802
    電話:86-21-64860708/64860576/64860572  傳真:86-21-64860709
    課程:course@infotek.com.cn
    業務:sales@infotek.com.cn
    技術:support@infotek.com.cn
    官方微信
    掃一掃,關注訊技光電的微信訂閱號!
    Copyright © 2014-2025 訊技光電科技(上海)有限公司, All Rights Reserved. 滬ICP備10008742號-1
    国产香蕉尹人在线视频你懂的|少妇性荡欲午夜性开放视频剧场|出差被绝伦上司侵犯中文字幕|国产白袜脚足J棉袜在线观看|亚洲天天做日日做

      <strike id="ybkjs"><bdo id="ybkjs"></bdo></strike>

      <strike id="ybkjs"><blockquote id="ybkjs"></blockquote></strike>
      <label id="ybkjs"><sub id="ybkjs"><rt id="ybkjs"></rt></sub></label>
    1. <label id="ybkjs"></label>
    2. <label id="ybkjs"></label>

      <label id="ybkjs"></label>
      <legend id="ybkjs"></legend>