MATLAB: Save figure with filename from a cellarray

save

Hello. I have coordinate (X,Y) for a plot. I want to save the scatter plot using filename from another cellarray. I used this code: scatter(X,Y); savefig(Stncode(j,1),'.fig'); It returns an error : Error using savefig (line 35) H must be an array of handles to valid figures. How to save? I get the plot but I can't save the plot.
Thanks.

Best Answer

See the FAQ for good info on how to use cell arrays http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
If the filename is in another cell array like you said, then you can get the filename string from the cell array with braces:
filename = otherCellArray{index};
savefig(gcf, filename);