i have two problems in mathematica and want to do them in matlab:
measure := RandomReal[] - 0.5
m = 10000;
data = Table[measure, {m}];
fig1 = ListPlot[data, PlotStyle -> {PointSize[0.015]}]
Histogram[data]
matlab:
measure =@ (m) rand(1,m)-0.5
m=10000;
for i=1:m
data(:,i)=measure(:,i);
end
figure(1)
plot(data,'b.','MarkerSize',0.015)
figure(2)
hist(data)
And it gives me :
??? The following error occurred
converting from function_handle to
double: Error using ==> double
If i do :
measure =rand()-0.5
m=10000;
data=rand(1,m)-0.5
then, i get the right results in plot1 but in plot 2 the y=axis is wrong.
Also, if i have this in mathematica :
steps[m_] := Table[2 RandomInteger[] - 1, {m}]
steps[20]
Walk1D[n_] := FoldList[Plus, 0, steps[n]]
LastPoint1D[n_] := Fold[Plus, 0, steps[n]]
ListPlot[Walk1D[10^4]]
I did this :
steps = @ (m) 2*randint(1,m,2)-1;
steps(20)
Walk1D =@ (n) cumsum(0:steps(n)) --> this is ok i think
LastPointold1D= @ (n) cumsum(0:steps(n))
LastPoint1D= @ (n) LastPointold1D(end)-->but here i now i must take the last "folding"
Walk1D(10)
LastPoint1D(10000)
plot(Walk1D(10000),'b')
and i get an empty matrix and no plot..
Since @Itamar essentially answered your first question, here is a comment on the second one. You did it almost right. You need to define
since
cumsumis a direct analog ofFoldList[Plus,0,your-list]. Then, theplotin your code works fine. Also, notice that, either in your Mathematica or Matlab code, it is not necessary to defineLastPoint1Dseparately – in both cases, it is the last point of your generated list (vector)steps.EDIT:
Expanding a bit on
LastPoint1D: my guess is that you want it to be a last point of the walk computed byWalk1D. Therefore, it would IMO make sense to just make it a function of a generated walk (vector), that returns its last point. For example:Then, you use it as:
HTH