wolfram mathematica - Matrix catenation in MATLAB -


i have code in mathematica:

nxbin = table[{-5 sx + (i - 0.5)*step, nbin[[i]]}, {i, 1, length[nbin]}] 

and did in matlab:

a=zeros(length(nbin),1); nxbin=zeros(length(nbin),1); i=1:length(nbin)     anew=a*step*(i-0.5) -5*sx;     b=zeros(length(nbin(i)),1); nxbin(i,:)=[anew , b] end 

but matlab says

??? error using ==> horzcat
cat arguments dimensions not consistent.

error in ==> begin @ 52
nxbin(i,:)=[anew , b]

can tell me why error? also, can fewer lines?

you want catenate n-by-1 array nbin steps (probably x-values histogram). thus, can create "x-vector" , combine them.

nxbin = [ -5*sx + ((1:length(nbin))' - 0.5) * nstep, nbin(:)] 

here's same step-by-step

%# make vector values 1 nbin x = 1:length(nbin); %# transpose, since it's 1-by-n , want n-by-1 x = x'; %'# %# apply modification x x = -5*sx + (x-0.5)*nstep; %# catenate nbin (the colon operator guarantees it's n-by-1 nxbin = [x, nbin(:)]; 

edit

in case want plot this, can do

plot(nxbin(:,1),nxbin(:,2),'.') 

or, if guess right , it's histogram

bar(nxbin(:,1),nxbin(:,2)) 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -