The first thing that comes to my mind is that you can join the two Matlab function codes into one, so the occurrence of the condition is detected and the the condition could be executed.
Another solution could be to add a global variable as a flag to initialized the second Matlab function.
The last solution and the one I will explain deeply is to use the output of one Matlab function as the input of the second one. I propose you the next example solution:
I created a subsystem that generates a Random Integer between 0-4.
Random Integer Subsystem |
Random Number Source |
Random Integer Scope |
Now, the occurrence of the condition that is read by a Matlab function is that the random integer generated is greater than 1 or not. In the case the occurrence is true, the condition in the second Matlab function will be executed.
function y = fcn(u)
% If input is >1, output will be true (1), otherwise output will be false (0)
if u > 1
y = 1;
else
y = 0;
end
Output =1 if input is greater than one, Output = 0 if not |
Note: The integer could be saved in a global variable or could be inserted in Matlab function directly as an input variable. Sum is needed to be a global variable.
function y = fcn(u)
% If input is 1, output will the sum of the array, otherwise output will be
% 0.
global I;
global sum;
sum = sum + I;
if u
y = sum;
else
sum = 0;
y = 0;
end
Sumatory of the integers until output is reset |
Total system |
Dear Blanca,
ReplyDeletethis is exactly one which I did in my project but there is a problem with this way in large simulations which speed down the simulation!!!
As you know when a matlab function is triggered all of it's output signals must give values. imagine my function has two buses (each bus size is 32) as output which I want give new values to them if the mentioned condition is occurred else their past values must be kept. Using the proposed values I should use two memory modules to store the last values of buses and in each step of simulation write back these values to buses!!! the mentioned condition occurs rarely (one in 1000 steps). in this way the simulation speed down by a factor of 10!!!! and it lasts as much as two days.
I look a way to do value assignment to buses and some other computations only when the condition is occurred by checking the condition in one matlab function and trigger the other one.
hAY BRO I AM DOING SAME KING OF ASSIGNMENT AND YEAH NEED TO TRIGGER TWO MATLAB FUNCTIONS AS YOU TOLD HAVE YOU FOUND A WAY THEN PLEASE REPLY
DeleteThank You and I have a dandy present: Whole House Remodel Cost home renovation burnaby
ReplyDelete