我正在使用C#編寫的Matlab程序集。我得到了很多東西,但我遇到了一個問題。我有這樣一個類:如何在Matlab中處理非標準代表
classdef Mt4Class
% stuff left out
methods
function self = Mt4Class(theIp, thePort)
self.IP = theIp;
self.Port = thePort;
NET.addAssembly('C:\Program Files (x86)\MtApi\MtApi.dll');
self.apiClient = MtApi.MtApiClient();
end
function AddListenerQuoteUpdated(self, callback)
addlistener(self.apiClient, 'QuoteUpdated', callback);
end
function MyQuoteUpdate(~, ~, symbol, bid, ask)
disp(symbol, bid, ask);
end
end
end
然後我嘗試以下方法:
mtapi = Mt4Class('', 8222);
mtapi.AddListenerQuoteUpdated(@(~,~, symbol, bid, ask)mtapi.MyQuoteUpdate(0, 0, symbol, bid, ask));
然而,MATLAB回來了一個錯誤:
.NET events with nonstandard delegate definition are not supported in MATLAB.
我沒有源到Api。如果我這樣做了,將參數打包成EventArg
會很簡單。我也可以在我自己的程序集中封裝API庫,以便在sender, eventargs
表單中反映事件以符合Matlab,但這看起來很笨拙。有沒有解決的辦法?
我在下面的解決方案中提供了一些更多的細節 –