automate calculate total of images saved in a folder

i don't know how to type for the codings to automatic calculate the total of images saved as '.spm' in a folder and show the number of total on the designed interface using GUIDE.

댓글 수: 2

What is your question?
My question is about automatic calculate the total of images in a folder, i used the coding provided by Mr./Mrs/Miss Image Analyst and it works. Now i faced another problem is that i will have new folder for everyday, so how can i make it to automatic calculate the total of images in the folder everyday.

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

 채택된 답변

Image Analyst
Image Analyst 2015년 7월 10일
Try something like this:
filePattern = fullfile(yourFolder, '*.spm');
files = dir(filePattern);
numberOfFiles = length(files);
message = sprintf('Total number of spm files = %d', numberOfFiles);
set(handles.text1, 'String', message);

댓글 수: 8

Thank you very much for the codings!!
I would like to ask if everyday i will create a new folder to save images on that day, then how is the coding to let it automatic count the total of images in certain folder on the certain day? As an example: yesterday created a folder containing files , then the coding is : filePattern = fullfile('c:\dekstop\files\2015\October\6', '*.spm'); files = dir(filePattern); numberOfFiles = length(files); message = sprintf('%d', numberOfFiles); set(handles.text1, 'String', message);
then today i created a file again and the folder name will become 'c:\dekstop\files\2015\October\7', so how can i let it to automatic change to count the folder created everyday?
You can start at the top level and use genpath() to get a list of all subfolders. Then recurse into those and count the files in each folder. See attached demo.
Oh thank you so much!!! You really helped me alot!!
sorry that there is one more thing, if the files generated everyday were saved together in a same folder (Everyday will generates more than one file), how about if i want to calculate the amount if files generated on a specific day and specific time range? i will be using one pop-up menu to select time range and 3 pop-up menu to select day,month and year separately. I have no idea about the codings.
The files variable returned from dir has the state as one of the fields. I'd have to figure out how to parse the date and match it up with some dates that you somehow specify via a popup, listbox, or edit field, just like you would, so I'll let you do that.
ermm currently the folder is having few images with the modified date as shown below '07-Jul-2015 02:42:06' '06-Jul-2015 23:36:39' '07-Jul-2015 02:24:15' '07-Jul-2015 02:37:16' '06-Jul-2015 23:23:00' '07-Jul-2015 02:25:06' '07-Jul-2015 02:25:17' '06-Jul-2015 23:21:36' '06-Jul-2015 08:07:51' '06-Jul-2015 08:19:38', so how can i calculate the amount of images from 12am until 11.55am and amount of images from 12pm until 11.55pm?
I don't have anything ready to go for you so I suggest you look to build something with the date and time functions like datenum, datevec, month, day, year, etc.
Melindalee
Melindalee 2015년 7월 22일
편집: Melindalee 2015년 7월 22일
yea i do my searching on datenum, currently i just able to get the date and time of computer and play with deduction or subtraction of day, i still havent figure out how to get the modified date of files..
datenow = datestr(clock,0);
dateNowNum = datenum(datenow);
date12hrsBe4r = datestr(dateNowNum-0.50);
this just for finding current time and the time of 12 hours ago..i wanted to make it as a range and calculate how many files which their date and time are within this range, but i still have no idea on how to write the codings, do you still have any suggestion?
Melindalee
Melindalee 2015년 8월 5일
편집: Melindalee 2015년 8월 5일
I'd found the solution, anyway thank you very much =D

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2015년 7월 10일

편집:

2015년 8월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by