Add a variable within single quotes

6 visualizaciones (últimos 30 días)
Cheeesepondue
Cheeesepondue el 23 de En. de 2019
Comentada: Cheeesepondue el 24 de En. de 2019
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 comentarios
Cheeesepondue
Cheeesepondue el 24 de En. de 2019

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 23 de En. de 2019
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 comentarios
Cheeesepondue
Cheeesepondue el 23 de En. de 2019
Thanks! I thought about sprintf, but have not thought about writing a code that way.
Star Strider
Star Strider el 23 de En. de 2019
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by