replace the function "randperm" into code from embedded block SIMULINK

조회 수: 1 (최근 30일)
hi, I need to generate a c code from the next code wrote on an embedded editor from embedded block from simulink, but randperm is not supported by code generation, is there some way to do it?
thanks for you support
Size = 100
n = 50
pop = zeros(Size,n);
pop(1,:) = (1:n);
for k = 2:popSize
pop(k,:) = randperm(n);
end
  댓글 수: 1
Emmanuel Luevano
Emmanuel Luevano 2012년 11월 20일
btw, if I use eml.extrinsic to execute it, I understand that the operation is performed externally, but, it affect my code when this is done?

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2012년 11월 20일
randperm() is actually:
[~, p] = sort(rand(1,n))
Does this work in code generation?
In the current Matlab version, randperm uses the smarter Fisher-Yates-Shuffle, when 2 inputs are used. Would a corresponding C-Mex function work: FEX: Shuffle ?
  댓글 수: 2
Emmanuel Luevano
Emmanuel Luevano 2012년 11월 21일
these are good tips, I'll try with these, thanx, back with the results.
Jan
Jan 2012년 11월 21일
Another useful implementation of the Fisher-Yates-Shuffle in pure Matlab: http://www.mathworks.com/matlabcentral/fileexchange/30101-rpg-lab

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by