conversion from mathematica to matlab --> (appendto) -


i have following in mathematica , want use in matlab.i tried have mistakes , can't fixed them.it don't yet matlab philosophy! so,

intmc = {}; sigmat = {}; do[np1 = np + i*100;   xpoints = table[randomreal[], {z1, 1, np1}];   a1t = table[f[xpoints[[i2]]], {i2, 1, np1}];   a12 = standarddeviation[a1t]/sqrt[length[a1t]];   appendto[intmc, {np1, mean[a1t], a12}];   appendto[sigmat, {np1, a12}],   {i, 1, ntr}]; 

i did this:

  fx=@ (x) exp(-x.^2);      intmc=zeros();     sigmat=zeros();      i=1:ntr         np1=np+i*100;         xpoints=randn(1,np1);         k=1:np1         a1t=fx(xpoints(k))         end                   %--> until here prints results,but in                                %end gives                                % me message " attempted access xpoints(2,:);                               %index out of bounds because size(xpoints)=[1,200]                               %and stops executing.      %a1t=fx(xpoints(k,:))    %  -->i tried instead of above     %a1t=bsxfun(@plus,k,1:ntr)   % doesn't work          a12=std(a1t)/sqrt(length(a1t))         intmc=intmc([np1 mean(a1t) a12],:) %--> can't handle these 3 ,         sigmat=sigmat([np1 a12 ],:)        %as said stopped executing      end 

in order append scalar matlab array, can call either array(end+1) = value or array = [array;value] (replace semicolon comma if want 1-by-n array). latter works appending arrays; append arrays former, you'd call array(end+1:end:size(newarray,1),:) = newarray in case want catenate along first dimension.

however, appending in loops more than, say, 100 iterations, bad idea in matlab, because slow. you're better off pre-assigning array first - or better, vectorizing computation don't have loop @ all.

if understand correctly, want calculate mean , sem growing number of samples normal distribution. here's how can loop:

intmc = zeros(ntr,3); %# stores, on each row, np1, mean, sem sigmat = zeros(ntr,2); %# stores, on each row, np1 , sem  i=1:ntr %# draw np+100*i distributed random values np1 = np+i*100; xpoints = randn(np1,1); %# if want use uniform random values (as in randomreal), use rand %# also, can apply f(x) directly on array xpoints  %# caculate mean, sem m = mean(xpoints); sem = std(xpoints)/sqrt(np1);  %# store intmc(i,:) = [np1, m, sem]; sigmat(i,:) = [np1,sem];  end %# loop on 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -