matlab - How to plot normal distribution along a line? -


i working on matlab code plot normal distribution samples along line. keeping things simple question, using line y=10.

a=randn(300,2); x=a(:,1)'; y=a(:,2)'; x=[1.5*x(1:100)+5 1.5*x(101:200)+10 1.5*x(201:300)+15]; y=[1.5*y(1:100)+10 1.5*y(101:200)+10 1.5*y(201:300)+10]; plot(x,y,'marker','.','linestyle','none') axis ( [ 1 20 1 20 ] ) ; 

the aim this:

normal distribution along line

my problem is, code seems inefficient, these 2 lines:

x=[1.5*x(1:100)+5 1.5*x(101:200)+10 1.5*x(201:300)+15]; y=[1.5*y(1:100)+10 1.5*y(101:200)+10 1.5*y(201:300)+10]; 

in actual code however, expanded like

x=[1.5*x(1:100)+5 1.5*x(101:200)+10 1.5*x(201:300)+15 1.5*x(301:400)+20 1.5*x(401:500)+25 ................]; 

is there way can make more efficient, using loops or vectorization? trying understand how that, able find simple examples. can't understand how iterate 2 variables, 1 in range part x(201:300)....x(301:400) , 1 in addition part +15...+20

also, technique using plot normal distribution samples along line right technique, or there better / simpler method?

what want can done bsxfun: align each type of variation in different dimension, , let singleton expansion compute "combinations":

a = randn(300,2); offsets_x = [5 10 15]; % or offsets_x = (1:size(a,1)/chunk_size)*5 offsets_y = [10 10 10]; chunk_size = 100; x = bsxfun(@plus, 1.5*reshape(a(:,1), chunk_size, []), offsets_x); y = bsxfun(@plus, 1.5*reshape(a(:,2), chunk_size, []), offsets_y); x = x(:).'; y = y(:).'; 

from matlab r2016 onwards, implicit expansion can replace bsxfun lines simpler

x = 1.5*reshape(a(:,1), chunk_size, []) +  offsets_x; y = 1.5*reshape(a(:,2), chunk_size, []) +  offsets_y; 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -