Clear Filters
Clear Filters

Set properties of a COM-server that take an argument

1 view (last 30 days)
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.

Answers (1)

Adeline
Adeline on 11 Aug 2023
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 Comment
Stefan
Stefan on 11 Aug 2023
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.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!