A Code Monkey's Blog

Octave: save a figure to a file

I'm playing around Octave recently. As many other open-source projects, the documentation is not complete, or more precisely speaking, not friendly to new user. When I want to save a picture to the disk, the documentation tells me to use print(), but I still need to try several times before get it straight. Here is my example.

for i=1:11
surf(x,y,ue((i-1)*0.2));
filename = sprintf("us_t%d.png", i-1);
print(filename, '-dpng'); % Note the quote
end

BTW: I'm very grateful for the high compatibility of Octave code with Matlab code.