How to have Matlab access variables of activity simulation

Moderator: Moderators

How to have Matlab access variables of activity simulation

Postby ohs18 » Thu Jan 21, 2021 10:25 am

Hello,

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.
ohs18
Forum Newbie
Forum Newbie
 
Posts: 17
Posts Rating:1
Joined: Wed Jan 20, 2021 7:08 pm

Re: How to have Matlab access variables of activity simulation

Postby saulius_p » Mon Jan 25, 2021 2:38 pm

Hello,

Good to talk to you. I'm sure you saw this video: https://youtu.be/qo9JUhqCuiI. 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?

Sincerely,
Saulius
You do not have the required permissions to view the files attached to this post.
Best regards,
Saulius Pavalkis
User avatar
saulius_p
No Magic
No Magic
 
Posts: 326
Posts Rating:12
Joined: Fri Dec 04, 2009 5:37 am
Full name: Saulius Pavalkis

Re: How to have Matlab access variables of activity simulation

Postby ohs18 » Mon Jan 25, 2021 4:30 pm

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.

Console_error_display.PNG

Variable_pane.PNG

activity_diagram.PNG
You do not have the required permissions to view the files attached to this post.
ohs18
Forum Newbie
Forum Newbie
 
Posts: 17
Posts Rating:1
Joined: Wed Jan 20, 2021 7:08 pm


Return to Cameo Simulation Toolkits

Who is online

Users browsing this forum: No registered users and 0 guests