Auto generate variable name and save to file?

8 visualizzazioni (ultimi 30 giorni)
Huseyin
Huseyin il 19 Mag 2014
Commentato: Alvindra Pratama il 13 Giu 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

Risposte (1)

Image Analyst
Image Analyst il 20 Mag 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 Commento
Alvindra Pratama
Alvindra Pratama il 13 Giu 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?

Accedi per commentare.

Categorie

Scopri di più su Images in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by