Error when using level 2 matlab s-function
Mostrar comentarios más antiguos
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
Respuestas (1)
Walter Roberson
el 29 de Jun. de 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 comentarios
Ikram Jaouadi
el 30 de Jun. de 2017
Editada: Ikram Jaouadi
el 30 de Jun. de 2017
Walter Roberson
el 30 de Jun. de 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
el 1 de Jul. de 2017
Editada: Walter Roberson
el 1 de Jul. de 2017
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!