1
votes

I have this problem in Mathematica :

  L=16;
  f[x_]:=-x;
  mlat = Table[2 RandomInteger[] - 1, {L}, {L}];
  ArrayPlot[mlat, ColorFunction -> (If[# == 1, White, Black] &), Mesh -> All]

and I did this in Matlab:

 L=16;
 f=@ (x) -x;
 mlat=2*randint(L,L)-1;
    if mlat(:,:)==1   
      plot(mlat,'ws')
      hold on
    else
        plot(mlat,'ks')
        hold off
        grid on
    end

but I can't get the graph.

1
I don't know Mathematica, what are your graph supposed to look like? - Ghaul
It's from the ising model.It supposes to have squares,white and black. - George
@Ghaul: See the examples in the Mathematica help - Jonas

1 Answers

2
votes

First, you want to create an array with only ones and zeros, which you do using randi

L = 16;
mlat = 2*(randi([0,1],L,L)-0.5);

Then, you can display this as an image (I like to open an new figure for every plot)

figure
imshow(mlat,[]) %# [] scales to min...max

To make the image bigger, set axes size to 90% of the figure window

set(gca,'Units','normalized','Position',[0.05 0.05 0.9 0.9],'visible','on')

enter image description here

Note that the axes label correspond to the index of matrix elements, so (1,1) is top left.