Thursday, December 10, 2009

How to print nice figure on matlab

Here is an example that can print current figure to a eps file with DPI=300 .

figure;
print(gcf, '-depsc','-r300', figname);

"gcf" means the current figure. "-depsc" means save as eps color image. "-r300" means 300dpi, "figname" should be something like "name.eps"

Monday, December 7, 2009

Mimimum distance from point to a curve

1. Assume we already know the function of curve: y=f(x); Given a point p(x1,y1), calculate the minimum distance:

D=sqrt((x-x1)^2+(y-y1)^2);

D*=(x-x1)^2+(y-y1)^2;

substitute y by f(x);

D*=(x-x1)^2+(f(x)-y1)^2;

Compute the derivative of D* and set it to zero: D*'=0, then we can solve x; substitute x , we get minimum distance D*;

2. The other one is no function expression of curve. We need calculate all points.