蜜芽久久夜色精品国产免费_国产黄色片在线观看_99re8精品视频在线播放_国产精品午夜爆乳美女

訊技光電公司首頁 最新公告:2025年訊技課程安排發(fā)布啦! 黌論教育網(wǎng)校|English|蘇州訊技|深圳訊技|聯(lián)系我們|全站搜索
欄目列表
FRED
VirtualLab
Macleod
GLAD
OCAD
Optiwave
LASCAD
Litestar 4D
TechwizD和TX液晶顯示軟件
JCMSuite
EastWave
PanDao
光學(xué)實驗教具
最新發(fā)布

天文光干涉儀

雙折射晶體偏振干涉效應(yīng)

顏色分析

FRED應(yīng)用:顏色分析

FRED應(yīng)用:數(shù)字化極坐標(biāo)數(shù)據(jù)

FRED應(yīng)用:波片模擬

FRED應(yīng)用:MTF的計算

FRED應(yīng)用:LED手電筒模擬

FRED應(yīng)用:模擬沃拉斯頓棱鏡

FRED應(yīng)用:準(zhǔn)直透鏡模擬與優(yōu)

當(dāng)前位置: 主頁 > 服務(wù)項目 > 案例分析 > FRED >
FRED如何調(diào)用Matlab
時間:2016-01-18 21:23來源:訊技光電作者: 技術(shù)部點擊:次打印
簡介:FRED作為COM組件可以實現(xiàn)與Excel、VB、Matlab等調(diào)用來完成龐大的計算任務(wù)或畫圖,本文的目的是通過運行一個案例來實現(xiàn)與Matlab的相互調(diào)用,在此我們需要借助腳本來完成,此腳本為視為通用型腳本。
 
配置:在執(zhí)行調(diào)用之前,我們需要在Matlab命令行窗口輸入如下命令:
enableservice('AutomationServer', true)
enableservice('AutomationServer')
結(jié)果輸出為1,這種操作方式保證了當(dāng)前的Matlab實體可以用于通信。
 
在winwrp界面,為增加和使用Matlab類型的目錄庫,我們需要如下步驟:
1. 在FRED腳本編輯界面找到參考.
2. 找到Matlab Automation Server Type Library
3. 將名字改為MLAPP
 
 
在Matlab里面有兩種常用的數(shù)據(jù)發(fā)送選項PutWorkspaceData 及PutFullMatrix,PutWorkspaceData適用于存儲一般的數(shù)據(jù)在工作區(qū),并賦予其為變量,PutFullMatrix試用于復(fù)數(shù)數(shù)據(jù)。
 
圖 編輯/參考
 
 
現(xiàn)在將腳本代碼公布如下,此腳本執(zhí)行如下幾個步驟:
1. 創(chuàng)建Matlab服務(wù)器。
2. 移動探測面對于前一聚焦面的位置。
3. 在探測面追跡光線
4. 在探測面計算照度
5. 使用PutWorkspaceData發(fā)送照度數(shù)據(jù)到Matlab
6. 使用PutFullMatrix發(fā)送標(biāo)量場數(shù)據(jù)到Matlab中
7. 用Matlab畫出照度數(shù)據(jù)
8. 在Matlab計算照度平均值
9. 返回數(shù)據(jù)到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畫圖如下:
 
并在工作區(qū)保存了數(shù)據(jù):
 

 
并返回平均值:
 
與FRED中計算的照度圖對比:
   
例:
 
此例系統(tǒng)數(shù)據(jù),可按照此數(shù)據(jù)建立模型
 
系統(tǒng)數(shù)據(jù)
 
 
光源數(shù)據(jù):
Type: Laser Beam(Gaussian 00 mode)
Beam size: 5;
Grid size: 12;
Sample pts: 100;
相干光;
波長0.5876微米,
距離原點沿著Z軸負(fù)方向25mm。
 
對于執(zhí)行代碼,如果想保存圖片,請在開始之前一定要執(zhí)行如下代碼:
enableservice('AutomationServer', true)
enableservice('AutomationServer')
關(guān)于我們
公司介紹
專家團隊
人才招聘
訊技風(fēng)采
員工專區(qū)
服務(wù)項目
產(chǎn)品銷售
課程中心
專業(yè)書籍
項目開發(fā)
技術(shù)咨詢
聯(lián)系方式
地址:上海市嘉定區(qū)南翔銀翔路819號中暨大廈18樓1805室    郵編:201802
電話:86-21-64860708/64860576/64860572  傳真:86-21-64860709
課程:[email protected]
業(yè)務(wù):[email protected]
技術(shù):[email protected]
官方微信
掃一掃,關(guān)注訊技光電的微信訂閱號!
Copyright © 2014-2025 訊技光電科技(上海)有限公司, All Rights Reserved. 滬ICP備10008742號-1