How can I set the file name as my title name in a subfolder for numerous plots
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to set the title name (that varies depending on the plot) as the file name in a subfolder. I get the error code: Error using sprintf. Function is not defined for 'cell' inputs.
So there is some mistake with my syntax. I have tried different approaches but I don't get it to work. My code is as follows:
figure Timestep=(1:length(d_f_t(:,1)))'; plot(Timestep,W_per_K_serie, '*'); title(['Byggnad', subfolderNames(b)])
folder_path='PathXXX';
saveas(fullfile(folder_path, sprintf('%s.jpg',get(get(gca,'title'),'string'))));
Does anybody have any advice? Thank you in advance
2 个评论
采纳的回答
Stephen23
2018-5-23
编辑:Stephen23
2018-5-24
The title 'String' property may be a cell array, string array, or a char vector. You can easily convert this into a char vector:
tmp = char(get(get(gca,'title'),'string'));
saveas(figH, fullfile(folder_path, sprintf('%s.jpg',tmp)));
I would recommend that you avoid gca, gcf, etc., and always obtain and use explicit graphics handles for all graphics objects that you need to refer to.
7 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!