Error when using level 2 matlab s-function
显示 更早的评论
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
回答(1 个)
Walter Roberson
2017-6-29
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 个评论
Ikram Jaouadi
2017-6-30
编辑:Ikram Jaouadi
2017-6-30
Walter Roberson
2017-6-30
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
2017-7-1
编辑:Walter Roberson
2017-7-1
类别
在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!