How to print index number when ploting figures from functions

조회 수: 3 (최근 30일)
lena kappa
lena kappa 2022년 9월 18일
댓글: Adam Danz 2022년 9월 19일
Hello everyone!
I have written the next piece of code that calls a funtions and saves the 4 figures that are created from that function for every image in a folder but the images are overwritten because i cant index the images inside the function.
This is my code :
folder = 'C:\Users\lena\Desktop';
outLoopValues = [1,2];
for k = 1 : length(outLoopValues)
index = outLoopValues(k);
thisBaseFileName = sprintf('%d.png', index);
thisFileName = fullfile(folder, thisBaseFileName);
images{index} = imread(sprintf('%d.png', index));
[f1, f2, f3, f4] = an_function(images{index})
end
So an_function takes my images as inputs and makes the 4 figures as outpouts but i dont know how to change the name inside each one of the figures in the function so that it is saved lets say with f1image_index1 for the first index and f1image_index2 for the second index
  댓글 수: 2
Jan
Jan 2022년 9월 18일
Just a note: You create the file name with the folder as thisFileName, wo why don't you use it?
What about providing k or index as further input to the function an_function? Or you can set the names of the figures afterwards:
set(f1, 'Name', sprintf('f%dimage_%d', k, index), 'NumberTitle', 'off'))
... and so on
Adam Danz
Adam Danz 2022년 9월 19일
To add to @Jan's advice, if you want to avoid overwriting the files if you run the function again on the same set of data, you could add a datetime stamp to the filenames.
timenow = datetime('now','format','yyMMddHHmmss');
sprintf('f%dimage_%d_%s', k, index, timenow)

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

답변 (0개)

카테고리

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