1

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.

3
  • I don't know Mathematica, what are your graph supposed to look like? Commented Feb 18, 2011 at 13:38
  • It's from the ising model.It supposes to have squares,white and black. Commented Feb 18, 2011 at 13:43
  • @Ghaul: See the examples in the Mathematica help Commented Feb 18, 2011 at 13:46

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

9 Comments

Hello,i am looking at it now,i edited my post.I have a function f.
@George: And this function f does what?
It is the spin reverse operator.I don't know how to implement it in my loop.
And the mlat has only values -1 and 1,not 0 and 1 as you said.I think i have this right.
@George: Oh, I missed the thing with -1 and 1. I'm editing this right away.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.