«

»

Oct
31

Matlab peculiarities

Hello readers!

So while working on my Neural Networks homework, I stumbled across an interesting problem when using the surf command in Matlab. Try running the following commands:

Xi = -2 + [0:20]*0.2;
Xj = -2 + [0:20]*0.2;
X = zeros(2,size(Xi,2)*size(Xj,2));
for i = 1:size(Xi,2)
n = (i-1) * size(Xj,2);
for j = 1:size(Xj,2)
X(:,n + j) = [Xi(i); Xj(j)];
end
end
Y = -1 + double((X(1,:).^2 + X(2,:).^2)
surf(Xi,Xj,reshape(Y,size(Xi,2),size(Xj,2)))

Running this on two different machines produces different graphs:
Good matlab image vs Bad Matlab image

The first image is the correct output. Note how in the second image, the top-right corner of the cylinder is chopped off. Check your Matlab and see what it outputs. Both of these images were done using Matlab 2007a. If you have a version that doesn’t output the correct graphs, a remedy to the problem is to go to “Edit”->”Copy Figure”, it will either rerender the image on the screen, or at worst put the correct image into the copy buffer.

Fekete András

1 comment

  1. Andrew Kun says:

    This problem did appear on my machine.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>