output variable size matrix, while its specified type is something else.
4 views (last 30 days)
Show older comments
Hi There
I want to generate random number based on its probability and i found the following code online
for time1=0:10:100;
r=rand;
prob=[.5,.1,.4];
prob=cumsum(prob);
value=[6,7,8]; %values corresponding to the probabilities
ind=find(r<=prob,1,'first');
x=value(ind)
end
it is working fine on Matlab however on Simulink it gives me the following error:
''Data 'x' (#79) is inferred as a variable size matrix, while its specified type is something else. ''
I changed the size of x and makes it 'variable size' then i received the following message:
''Output 'x' (#79) has variable size but the upper bound is not specified; explicit upper bound must be provided. ''
What i Want is: generating one random number from (6, 7, 8) based on its probability at each for loop.
Many Thanks in advance.
0 Comments
Accepted Answer
AJ von Alt
on 10 Sep 2014
MATLAB Function Block is having difficulty inferring the size of x.
Replacing
x=value(ind);
with
x=value(ind(1));
should fix this.
More Answers (0)
See Also
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!