SimEvents: Why do I get the error "undefined function or variable 'out1'" in testEntry method?

2 views (last 30 days)
I have modeled a simple server that encounters failure. I want the testEntry method to close the gate of Storage1, when the Failure event is arrived in Storage2. The DES system also outputs some statistics about its status. But it seems that my code has issues with the body of testEntry method, where I want to update signal outputs. Each time I run the model, it throws the following error:
% 'undefined function or variable 'out1'.
% The first assignment to a local variable deterines its class.'.
% The error occurred for MATLAB System block
% 'SimpleServer/MATLAB Discrete-Event System'.
I have written the DES system object file step-by-step and I think the testEntry causes this error, because it was the last method I added. When I remove this method, the model works with no errors. Files are attached.

Answers (1)

Ashitha Mahendra
Ashitha Mahendra on 14 Feb 2020
Hi Kar Moh,
If my understanding is not wrong, you are trying to observe the output from the Discrete Event System (DES) block. I also think that testEntry is the function which is causing the error. I see that out1, out2, out3 are not declared as the output.
Usually, any output from the DES block is declared before it is used in any event as shown below:
function [o1,o2,o3] = getOutputNamesImpl(~)
o1 ='out1' ;
o2 ='out2' ;
o3 ='out3' ;
end
You can have look at this link below, where there are two inputs to the DES block similar to your case but with 3 outputs:https://www.mathworks.com/help/simevents/examples/selection-server-select-specific-entities-from-server.html.
You can also try executing the following command alternatively for opening the example in MATLAB:
>>seExampleSelectionServer
This example shows how you can use the MATLAB DES block to write a custom N-Server from which specific entities can be selected using a key lookup. Passengers enter from the IN port of the block and are stored in the block until a message arrives at the KEY port carrying a lookup key (KEY and IN are the inputs which you can have look at and change it accordingly for outputs)
Feel free to look at the link below if you have any questions with syntax of any DES block. The link also has a good number of examples:
Hope this helps to resolve the issue.
  1 Comment
Abdolkarim Mohammadi
Abdolkarim Mohammadi on 14 Feb 2020
Hi Ashitha,
As far as I know, getOutputNamesImpl is used to determine the labels of the outputs that appear on the block diagram, and are not the port names to be used in block's code. The port names are declared in getEntityPortsImpl according to the documentation, where event ports get names and signal ports should be declared as ''. In the methods, in1, in2, ... and out1, out2, ... are used. In the attatched model, if you comment out the TaskTestEntry method, the model works fine.

Sign in to comment.

Categories

Find more on Queue, Service, and Route Modeling in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!