Wednesday, April 14, 2010

Sampling within the range

Explore and get me values that I want within the range

close all
clc
clear all
m = 23;
n = 34;
jumpSTEP = 11;
broken = 1;
playX = [-3:0.1:3];
playY = [-3:0.1:3];
reject = 1;
for jj = 1:1000
    notOK = 1;
    while notOK
        m = m + ceil(jumpSTEP*rand);
        n = n + ceil(jumpSTEP*rand);
        m = rem(m,length(playX));
        n = rem(n,length(playY));
        saveM(jj) = m;
        saveN(jj) = n;
        if m<1
            reject = reject+1;
            continue
        end
        if n<1
            reject = reject+1;
            continue
        end
        if m>1
            notOK =0;
        end
        if n>1
            notOK =0;
        end

    end
end
figure
plot([1:1000],saveM, 'or');
hold on
plot([1:1000],saveN, 'ok');
plot([1:1000], 1, [1:1000], length(playX) );
min(saveM)
min(saveN)


No comments: