Embedded Matlab function to save a random number
Show older comments
Hi,
I want to write an Embedded Matlab function to store the ramdom number of the Random Generator block into a vector, something like 'To Workspace' block.
The code is following: function fcn(u) eml.extrinsic('assignin'); eml.extrinsic('evalin'); % index initialization persistent index; if isempty(index) index = 0; end;
% every time a new index
index = index + 1;
% save the variables in workspace
assignin('caller', 'a', u);
assignin('caller', 'b', uint16(index));
evalin('caller', 'c(uint16(b)) = a');
The variable 'c' is defined in a function which runs the 'sim()' command. c = zeros(1000, 1);
There is an error: In an assignment A(I) = B, the number of elements in B and I must be the same.
which relates to this line:
evalin('caller', 'c(uint16(b)) = a');
Could anybody help me to solve this problem?
Thanks Senmeis
Accepted Answer
More Answers (1)
Owen
on 24 Oct 2012
0 votes
1 Comment
Kaustubha Govind
on 24 Oct 2012
Does the "Random Number Generator" block have a dialog setting to change it from frame-based data to sample-based data? That might be the right thing to do here.
Categories
Find more on General Applications in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!