Prev: Question of Fourier Transoform of a transposed matrix? Thanks a
Next: having text or file names as variables
From: Matthew on 26 Jul 2010 23:53 Hi MatLab wizards I'm trying to generate a function call from within a MATLAB Embedded Function (within a Discrete Event Subsystem) using the following script (using Simulink and SimEvents): ----------------- function fcn(time,matrix) A=matrix; B=time; for i=1:1:length(A) if A(i)==B; GenerateCall() end end ----------------- In this case the 'time' variable is driven by the SimuLink standard clock function and the matrix is a constant of size 1x10. The function call is then fed to an Event Based Entity Generator and counted. While the Matrix is only 10 long, I seem to be generating 20 entities. Instrumenting through using eml.extrinsic('disp') shows it seems to be looping twice, when I only want it to execute once. How do I stop this from happening? Is there a better way to achieve the same result? cheers
From: Walter Roberson on 27 Jul 2010 00:05 Matthew wrote: > function fcn(time,matrix) > > A=matrix; > B=time; > > for i=1:1:length(A) > if A(i)==B; > GenerateCall() > end > end Is your code perchance equivalent to function fcn(time,matrix) if any(matrix == time) GenerateCall(); end end
From: Matthew on 27 Jul 2010 02:30 Walter Roberson <roberson(a)hushmail.com> wrote in message <YVs3o.31364$o27.29374(a)newsfe08.iad>... > Is your code perchance equivalent to > > function fcn(time,matrix) > if any(matrix == time) > GenerateCall(); > end > end Hi Walt, Unfortunately no, because the above code only would generate one function call in a singular time step. Sorry, I should have explained that my 1x10 matrix is equivalent to: [0;0;0;0;0;0;0;0;0;0] So I am trying to generate 10 entities at time zero or any combination of simulateous entities at any timestep. The above matrix with my code produces 20 function calls because the matrix is looped twice but why its looping twice I'm not sure. Using your code I 'should' only produce 1 entity with the above matrix but I still had the problem of two entities being created. Thank you for your help and I look forward to your response Matt
From: Matthew on 27 Jul 2010 02:58 I think I have solved the problem though. Taking the embedded mathlab function from inside the Discrete Event Subsystem seems to have stopped the double generation. So I can conclude that the double generation is due to the operation of the Discrete Event Subsystem, although how it managed to cause this error I would still be interested in learning so that I don't inadvertently make the mistake somewhere else. Matt
From: Steve Amphlett on 27 Jul 2010 02:59 "Matthew " <mcdmj96(a)yahoo.co.uk> wrote in message <i2ludj$nh2$1(a)fred.mathworks.com>... > Walter Roberson <roberson(a)hushmail.com> wrote in message <YVs3o.31364$o27.29374(a)newsfe08.iad>... > > Is your code perchance equivalent to > > > > function fcn(time,matrix) > > if any(matrix == time) > > GenerateCall(); > > end > > end > > Hi Walt, > > Unfortunately no, because the above code only would generate one function call in a singular time step. Sorry, I should have explained that my 1x10 matrix is equivalent to: > > [0;0;0;0;0;0;0;0;0;0] > > So I am trying to generate 10 entities at time zero or any combination of simulateous entities at any timestep. The above matrix with my code produces 20 function calls because the matrix is looped twice but why its looping twice I'm not sure. > > Using your code I 'should' only produce 1 entity with the above matrix but I still had the problem of two entities being created. > > Thank you for your help and I look forward to your response > > Matt Does a function call subsystem not do what you want?
|
Next
|
Last
Pages: 1 2 Prev: Question of Fourier Transoform of a transposed matrix? Thanks a Next: having text or file names as variables |