Auto generate variable name and save to file?

8 visualizaciones (últimos 30 días)
Huseyin
Huseyin el 19 de Mayo de 2014
Comentada: Alvindra Pratama el 13 de Jun. de 2016
Hi,
I'am working on GUI and have a file named 'work.mid' .I made some applications on it and want to save it as 'work1.mid' when I click the save button automatically to 'c:\saved_datas\. And when I click that button second time, I want to save it as 'work2.mid', on the third time 'work3.mid' etc. The function must work like that on the background. Simple the code is,
nmat=readmidi_java('work.mid');
Name = fullfile('c:\saved_datas\', '?????' );
writemidi_java(nmat,Name);
At '?????', there should be a variable like N, so 'workN.mid' will be saved like work1.mid, work2.mid...
Thanks

Respuestas (1)

Image Analyst
Image Analyst el 20 de Mayo de 2014
Just make a global variable called datasetNumber or something. Then create the file name
global datasetNumber;
baseFileName = sprintf('work%d.mid', datasetNumber);
fullFileName = fullfile('c:\saved_datas\', baseFileName);
datasetNumber = datasetNumber +1; % Increment for next time.
  1 comentario
Alvindra Pratama
Alvindra Pratama el 13 de Jun. de 2016
i have code like this :
global datasetNumber;
img = getframe(gca);
baseFileName = sprintf('%d.jpg', datasetNumber);
filename = fullfile(fullfile('H:\SKRIPSI\Citra Latih 2\', baseFileName));
imwrite(rgb2gray(img.cdata),filename,'jpg');
datasetNumber = datasetNumber +1; % Increment for next time.
I want to save an image from an axes, when I save by using the code above, each of the image does not have a file name. I want to save the image that have a file name like 1.jpg, 2.jpg, 3.jpg, and so on without any restrictions in the store a lot of images. how can I make that?

Iniciar sesión para comentar.

Categorías

Más información sobre Images 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