久久精品国产亚洲av瑜伽-日本理伦片午夜理伦片-大胆gogo高清在线观看-成熟人妻av无码专区

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

天文光干涉儀

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

顏色分析

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

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

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

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

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

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

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

FRED如何調(diào)用Matlab
時(shí)間:2016-01-18 21:23來(lái)源:訊技光電作者: 技術(shù)部點(diǎn)擊:次打印
簡(jiǎn)介:FRED作為COM組件可以實(shí)現(xiàn)與Excel、VB、Matlab等調(diào)用來(lái)完成龐大的計(jì)算任務(wù)或畫圖,本文的目的是通過(guò)運(yùn)行一個(gè)案例來(lái)實(shí)現(xiàn)與Matlab的相互調(diào)用,在此我們需要借助腳本來(lái)完成,此腳本為視為通用型腳本。
 
配置:在執(zhí)行調(diào)用之前,我們需要在Matlab命令行窗口輸入如下命令:
enableservice('AutomationServer', true)
enableservice('AutomationServer')
結(jié)果輸出為1,這種操作方式保證了當(dāng)前的Matlab實(shí)體可以用于通信。
 
在winwrp界面,為增加和使用Matlab類型的目錄庫(kù),我們需要如下步驟:
1. 在FRED腳本編輯界面找到參考.
2. 找到Matlab Automation Server Type Library
3. 將名字改為MLAPP
 
 
在Matlab里面有兩種常用的數(shù)據(jù)發(fā)送選項(xiàng)PutWorkspaceData 及PutFullMatrix,PutWorkspaceData適用于存儲(chǔ)一般的數(shù)據(jù)在工作區(qū),并賦予其為變量,PutFullMatrix試用于復(fù)數(shù)數(shù)據(jù)。
 
圖 編輯/參考
 
 
現(xiàn)在將腳本代碼公布如下,此腳本執(zhí)行如下幾個(gè)步驟:
1. 創(chuàng)建Matlab服務(wù)器。
2. 移動(dòng)探測(cè)面對(duì)于前一聚焦面的位置。
3. 在探測(cè)面追跡光線
4. 在探測(cè)面計(jì)算照度
5. 使用PutWorkspaceData發(fā)送照度數(shù)據(jù)到Matlab
6. 使用PutFullMatrix發(fā)送標(biāo)量場(chǎng)數(shù)據(jù)到Matlab中
7. 用Matlab畫出照度數(shù)據(jù)
8. 在Matlab計(jì)算照度平均值
9. 返回?cái)?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中計(jì)算的照度圖對(duì)比:
   
例:
 
此例系統(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;
相干光;
波長(zhǎng)0.5876微米,
距離原點(diǎn)沿著Z軸負(fù)方向25mm。
 
對(duì)于執(zhí)行代碼,如果想保存圖片,請(qǐng)?jiān)陂_(kāi)始之前一定要執(zhí)行如下代碼:
enableservice('AutomationServer', true)
enableservice('AutomationServer')
關(guān)于我們
公司介紹
專家團(tuán)隊(duì)
人才招聘
訊技風(fēng)采
員工專區(qū)
服務(wù)項(xiàng)目
產(chǎn)品銷售
課程中心
專業(yè)書(shū)籍
項(xiàng)目開(kāi)發(fā)
技術(shù)咨詢
聯(lián)系方式
地址:上海市嘉定區(qū)南翔銀翔路819號(hào)中暨大廈18樓1805室    郵編:201802
電話:86-21-64860708/64860576/64860572  傳真:86-21-64860709
課程:course@infotek.com.cn
業(yè)務(wù):sales@infotek.com.cn
技術(shù):support@infotek.com.cn
官方微信
掃一掃,關(guān)注訊技光電的微信訂閱號(hào)!
Copyright © 2014-2024 訊技光電科技(上海)有限公司, All Rights Reserved. 滬ICP備10008742號(hào)-1