Hi
I getting text from excel cell A1. This value changes for different dataset.
Question: How to use it as a filename for saving image.
I am currently using saveas(gcf,'Test.jpg');
or saveas(gca, fullfile(folderName, 'Test'),'jpeg');
Thanks

7 件のコメント

TAB
TAB 2018 年 5 月 23 日
fname = xlsread('your_excel.xlsx', 'A1');
saveas(gcf, [fname '.jpg']);
Siva Ratnasingam
Siva Ratnasingam 2018 年 5 月 23 日
Thank for your reply.
Followed the code. I displayed fname and it shows the correct name but it is showing an error.
Invalid filename: .jpg
Paolo
Paolo 2018 年 5 月 23 日
Try
saveas(gcf,fname,'jpg')
Siva Ratnasingam
Siva Ratnasingam 2018 年 5 月 23 日
IT still show an error:
Error using saveas (line 96)
Invalid filename.
My code:
fname= xlsread('c:\data.xlsx','sheet1','a1');
saveas(gcf,fname, 'jpg'); also tried '.jpg'
disp(fname);
disp shows 'testing123'
invalid filename.
I tried
saveas(gcf,'testing123', 'jpg');
it saves as testing123.jpg
Paolo
Paolo 2018 年 5 月 23 日
Try
saveas(gcf,cell2mat(fname),'jpg')
Siva Ratnasingam
Siva Ratnasingam 2018 年 5 月 23 日
It works.
Thank you very much Paolo
Paolo
Paolo 2018 年 5 月 23 日
You are welcome, I wrote an answer for the question so that other people can easily find the solution if they are facing the same problem.

サインインしてコメントする。

 採用された回答

Paolo
Paolo 2018 年 5 月 23 日

1 投票

It does not work because the string contained in fname is wrapped inside a cell.
You must convert the cell to the data type contained within it.
Use:
saveas(gcf,cell2mat(fname),'jpg')

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFile Operations についてさらに検索

タグ

質問済み:

2018 年 5 月 23 日

コメント済み:

2018 年 5 月 23 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by