Set properties of a COM-server that take an argument

3 次查看(过去 30 天)
Hi,
I started to work with a COM-server, which provides some custom simulation capabilities. In principle, the underlying program has a GUI but for some tasks, using it is relatively laborious. Therefore, I want to operate it through MATLAB.
For the simulation routine, I have to change some predefined properties to new values. Most of them can be easily changed with for example:
COMServ=actxserver('server.name');
set(COMServ,"tolerance",1.0e-05)% or COMServ.tolerance=1.0e-05; etc.
But some of the properties e.g. 'fit_parameter_value' take an argument and are therfore handled in MATLAB as methods. For example, in fit_parameter_value(k) multiple parameters are stored (k=1,2,3...). Reading them is no issue as several alternatives work:
COMServ.fit_parameter_value(k);
fit_parameter_value(COMServ,k);
invoke(COMServ,'fit_parameter_value',k)
But I am unfortunately not able to set new values (maybe because I am using the wrong syntax). Neither of the following seems to work for me:
COMServ.fit_parameter_value(k)=newValue; %Unrecognized property 'fit_parameter_value' for class 'COM.server_name'.
fit_parameter_value(COMServ,k)=newValue; %Unable to use a value of type COM.server_name as an index.
invoke(COMServ,'fit_parameter_value',k)=newValue;%Unable to use a value of type COM.server_name as an index.
What would be the correct way to set these properties?
Thank you.

回答(1 个)

Adeline
Adeline 2023-8-11
You can change the property values by assigning the existing values to a handle and updating the property values through it.
For Example:
COMServ = actxserver('Matlab.Application'); % Create a server
ch = COMServ.interfaces; % Create a handle for the re. property
ch(1) = {'IMLApp'}; % Assign a value of choice to the property
In your case the following syntax can be followed:
MyHandle = COMServ.fit_parameter_value;
MyHandle(k) = newValue;
  1 个评论
Stefan
Stefan 2023-8-11
Hi,
Unfortunately, already creating the handle does not work as input parameters are still expected:
MyHandle = COMServ.fit_parameter_value;
--> Incorrect number or types of inputs or outputs for function 'fit_parameter_value'.
I contacted Mathworks Support regarding this issue a few days ago and it seems that it is not possible to set this due to COM limitations. They suggested using a .NET interface if possible.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by