Auto generate variable name and save to file?

8 Ansichten (letzte 30 Tage)
Huseyin
Huseyin am 19 Mai 2014
Kommentiert: Alvindra Pratama am 13 Jun. 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

Antworten (1)

Image Analyst
Image Analyst am 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 Kommentar
Alvindra Pratama
Alvindra Pratama am 13 Jun. 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?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by