Filter löschen
Filter löschen

how to write a function for iterative check between a randsample value and a fixed value.

1 Ansicht (letzte 30 Tage)
Dear all,
Can anyone please suggest me a way to write a function for the following example?
sim = normrnd(100,10,[10000,1]);
y = randsample(sim,1); x = 100; % sim is the results, which is calculated first. So "normrnd" is just for illustration purposes.
while(y < x) y = randsample(sim,1); end
just an iterative step until y>=x.
However, I need a function for this purpose, as this function will pass on to another function.
Thank you very much.

Akzeptierte Antwort

Oleg Komarov
Oleg Komarov am 19 Mär. 2011
function y = myRandSmpl(sim, x)
y = randsample(sim,1);
while y < x
y = randsample(sim,1);
end
end
Is that what you need?

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by