XLfile = dir('*.csv'); %List contents of the current folder
[~, index] = sort(str2double(regexp({XLfile.name},'\d+','match','once')));
XLfile = XLfile(index);
filename = {XLfile.name};
for k1=1:Num_of_files;
figure
plot(x{1,k1}, y{1,k1})
savefig('filename{1,k1}.fig');
fig = openfig('filename{1,k1}.fig');
end
Hello everyone,
I am wondering how I insert a variable inside single quotes.
Apparantly, the codes above (not complete codes. I just included essential parts) will not work. But I want to save figures with the n-th filename with extension of fig.
Thank you.

댓글 수: 4

madhan ravi
madhan ravi 2019년 1월 23일
Illustrate with an example of a string and tell exactly at which location the variable have to be inserted!
Cheeesepondue
Cheeesepondue 2019년 1월 23일
@madhan ravi you are right! thanks for letting me know. I will definitely do it next time.
Cheeesepondue
Cheeesepondue 2019년 1월 24일

댓글을 달려면 로그인하십시오.

 채택된 답변

Star Strider
Star Strider 2019년 1월 23일

0 개 추천

I have no idea what your ‘filename’ array is. If it is the name without the ‘.csv’ extension, something like this may work:
savefig(sprintf('%s.fig',filename{1,k1}))
For example:
k1 = 1;
filename{1} = 'My File';
q = sprintf('%s.fig',filename{1,k1})
q =
'My File.fig'
Experiment to get the result you want.

댓글 수: 2

Cheeesepondue
Cheeesepondue 2019년 1월 23일
Thanks! I thought about sprintf, but have not thought about writing a code that way.
Star Strider
Star Strider 2019년 1월 23일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2019년 1월 23일

댓글:

2019년 1월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by