MATLAB: Saving as of a figure with current folder name

saving as folder name

Hello ,how can i save my created figure with a name which involves the directory name , where the figure was created.
for example if i plot some graths inside a folder called "grades" then i would like to have the figure saved as a jpg file called grades_90,i dont know the name of the folder. It needs to save it as foldername_90 is there a way to do it ? i know there is a save as command but i dont know how to get the folder name and involve it in this command saveas(h,'filename.jpg')
Thanks

Best Answer

str = pwd ;
idx = strfind(str,'\') ;
foldername = str(idx(end)+1:end) ;
figurename = strcat(foldername,'_90','.jpg') ; % give your extension
plot(rand(10,1)) ;
saveas(gcf,figurename) ;