Auto generate variable name and save to file?

조회 수: 8 (최근 30일)
Huseyin
Huseyin 2014년 5월 19일
댓글: Alvindra Pratama 2016년 6월 13일
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

답변 (1개)

Image Analyst
Image Analyst 2014년 5월 20일
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
Alvindra Pratama
Alvindra Pratama 2016년 6월 13일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by