0
votes

I am a novice learner in Simulink. I have been trying to sort the uniform random numbers in ascending order using the Matlab Function block in Simulink. Somehow it did not work. Here is the code that I wrote in a MATLAB function

function y = fcn(u)
%#codegen

y =sort(log(u)/-0.0089);

Can anyone help me with this?

1
Why didn't it work? Did you get an error? If so, what was it. Are the numbers wrong? If so, give an example. - Phil Goddard
This part of the function looks good. How are you calling fcn, in other words, what is u? Please make a minimal, complete and verifiable example (stackoverflow.com/help/mcve). - mars
It did not give me any error. When I tried to view the result of y in scope, it is still in randomized order not in ascending order. The example is like this.I want to generate uniform random numbers from 0 to 1. So the u here is the uniform random number block from simulink (that is the input). And after that, I used Matlab function block. Here I have to write a matlab code that is function y=fcn(u) %#codegen y =sort(u); As far as I know, the simulink will automatically assign the uniform random number as u in the Matlab function block.I hope my explanation is clearer than before. - Nad

1 Answers

0
votes

Using exactly your function, the following model does as expected. What else are you doing?

enter image description here