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

Antworten (1)

Walter Roberson
Walter Roberson am 29 Jun. 2017

0 Stimmen

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
Ikram Jaouadi am 30 Jun. 2017
Bearbeitet: Ikram Jaouadi am 30 Jun. 2017
C:\Program Files\MATLAB\R2013a\toolbox\comm\commdeprecated\randint.m
when I used randint in a matlab function I got a true result
function qa = QProt(n)
qa = zeros(1,n);
for i=1:n
qa=randint(1,i,[0,1]);
end
end
Walter Roberson
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
Ikram Jaouadi am 1 Jul. 2017
Bearbeitet: Walter Roberson am 1 Jul. 2017
Thanks for your reply
I partially resolved the problem bye using this code
function Outputs(block)
x=block.InputPort(1).Data;
for i=1:x
block.OutputPort(1).Data(i)=randint(1,1,[0,1]);
block.OutputPort(2).Data(i)=randint(1,1,[0,1]);
block.OutputPort(3).Data(i)=randint(1,1,[0,1]);
end
%end Outputs
But when running I see changing values before having a final matrix. it's like if the loop is executed in the display.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 29 Jun. 2017

Bearbeitet:

am 1 Jul. 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by