Error when using level 2 matlab s-function
Ältere Kommentare anzeigen
I'm using simulink with system generator
I'm trying to write a level 2 s-function having as output 3 matrix of uniform random values (0 or 1)
I tried doing like this
for i=1:50
block.OutputPort(1).Data(i)=randint;
block.OutputPort(2).Data(i)=randint;
block.OutputPort(3).Data(i)=randint;
end
and like this also
for i=1:50
block.OutputPort(1).Data=randint(1,i,[0,1]);
block.OutputPort(2).Data=randint(1,i,[0,1]);
block.OutputPort(3).Data=randint(1,i,[0,1]);
end
and I have the same error
"Invalid assignment in 'PRNG/Level-2 MATLAB S-Function': attempt to assign a vector of width 2 to a vector of width 1"
Can you help me please
Thnks
Antworten (1)
Walter Roberson
am 29 Jun. 2017
Please show the output for
which -all randint
randint was obsoleted from the Communications Systems Toolbox starting in R2012a, and was removed a few releases later. When called in the syntax you are using it returned a single random value. I suspect that you are getting some third-party randint
3 Kommentare
Ikram Jaouadi
am 30 Jun. 2017
Bearbeitet: Ikram Jaouadi
am 30 Jun. 2017
Walter Roberson
am 30 Jun. 2017
Try running the loop in reverse, 50 down to 1. Remember that in acceleration mode, the first assignment to a variable determines the data type and size. You did not initialize to a vector of the final length so the first assignment to element 1 would set the size of the variable to be 1.
But my suggestion otherwise would be to use your second version except with just i=50 fixed instead of the for loop that assigns a random vector of length 1, overwrites that with a random vector of length 2, overwrites again with length 3 and so on.
Ikram Jaouadi
am 1 Jul. 2017
Bearbeitet: Walter Roberson
am 1 Jul. 2017
Kategorien
Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!