Auto generate variable name and save to file?

7 vues (au cours des 30 derniers jours)
Huseyin
Huseyin le 19 Mai 2014
Commenté : Alvindra Pratama le 13 Juin 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

Réponses (1)

Image Analyst
Image Analyst le 20 Mai 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 commentaire
Alvindra Pratama
Alvindra Pratama le 13 Juin 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?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by