Page 1 of 1

How to have Matlab access variables of activity simulation

PostPosted: Thu Jan 21, 2021 10:25 am
by ohs18

I am fairly new to running simulations while integrating with matlab. I am running a very simple activity diagram that consists of an initial node, an opaque action, and a flow final node. In the opaque action, I am calling a matlab script that attempts to utilize the variables in the variables pane of the simulation window by name. I do know that I have the correct variables running and available, as I am running the activity diagram with context.

However, when my matlab script attempts to access a variable from the cameo simulation (for example: x = my_variable), I receive the error "undefined function or variable 'my_variable' ". I am not sure why this is happening, because my_variable is one of the variables in the simulation window, and I was under the impression that once you run the "matlab.shareEngine" function in the command line window, the matlab workspace and simulation variables were all available for use by either matlab or cameo (depending on what you are trying to do).

Having matlab access and utilize the simulation variables seems like a very trivial task, so I do believe I am missing something pretty basic here, but have been struggling with this problem for a bit, so any help would be fantastic. Thanks.

Re: How to have Matlab access variables of activity simulation

PostPosted: Mon Jan 25, 2021 2:38 pm
by saulius_p

Good to talk to you. I'm sure you saw this video: Please find sample attached.

If you are following the steps in the video and still getting error could you make short video and attach to the post?


Re: How to have Matlab access variables of activity simulation

PostPosted: Mon Jan 25, 2021 4:30 pm
by ohs18
Hi Saulius,

Yes I have seen that video already. I tried to follow along as best as I could and apply what I saw in the video to my basic model I am using. However, I still get the previous error that I listed above.
I am not currently able to make a video of my model. However, I have attached my model file, along with a few pictures that I hope clarify my problem. The variable_pane.png picture shows the 4 variables (Lat, Lon, Name, and TOP) that my matlab script is attempting to use. For simplicity sake, I have just made my matlab script "basic_activity_integration" 3 lines long:

lat = Lat + 10;
lon = Lon + 10;
fprintf('%s is located at %d, %d', Name, lat, lon);

As soon as I run my activity diagram, called "create_basic_Scenario" which I have also attached as a picture, I receive the error, also attached as a picture. I have tried to simplify this model/integration simulation as much as possible to make it as readable as possible. And again, I do know that I have shared the matlab engine as well, as when I run "matlab.engine.isEngineShared," it returns a 1 for true. I am pretty confused, as I have tried a few different things to resolve this issue, but no matter what I have tried, it seems like when I run the matlab script from the opaque action, the matlab workspace cannot access my variables from my model and I get this error each time.

Thanks in advance for the help.