Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problem with counting images in a desired directory

Subject: Problem with counting images in a desired directory

From: Jong Hoong

Date: 15 Nov, 2010 12:47:04

Message: 1 of 4

Hi all,
I am having problem with my code which I need to count the number of images browsing from a path and displaying in a static text box. Here is my codes:
D = uigetdir('*.jpg');
numberfiles = numel(D);

set(handles.result,'String',numberfiles);

The text box shows me "45" while the folder only have 10 jpg images. What is the problem?

Subject: Problem with counting images in a desired directory

From: Sean de

Date: 15 Nov, 2010 15:37:03

Message: 2 of 4

"Jong Hoong " <jonghoong@hotmail.com> wrote in message <ibra48$dj0$1@fred.mathworks.com>...
> Hi all,
> I am having problem with my code which I need to count the number of images browsing from a path and displaying in a static text box. Here is my codes:
> D = uigetdir('*.jpg');
> numberfiles = numel(D);
>
> set(handles.result,'String',numberfiles);
>
> The text box shows me "45" while the folder only have 10 jpg images. What is the problem?

How about:

cd(uigetdir);
njpgs = numel(dir('*jpg'))

Subject: Problem with counting images in a desired directory

From: Jong Hoong

Date: 15 Nov, 2010 16:12:04

Message: 3 of 4

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ibrk2u$b8l$1@fred.mathworks.com>...
> "Jong Hoong " <jonghoong@hotmail.com> wrote in message <ibra48$dj0$1@fred.mathworks.com>...
> > Hi all,
> > I am having problem with my code which I need to count the number of images browsing from a path and displaying in a static text box. Here is my codes:
> > D = uigetdir('*.jpg');
> > numberfiles = numel(D);
> >
> > set(handles.result,'String',numberfiles);
> >
> > The text box shows me "45" while the folder only have 10 jpg images. What is the problem?
>
> How about:
>
> cd(uigetdir);
> njpgs = numel(dir('*jpg'))

thanks, Sean. I got it worked.

Subject: Problem with counting images in a desired directory

From: Walter Roberson

Date: 15 Nov, 2010 16:22:40

Message: 4 of 4

On 15/11/10 6:47 AM, Jong Hoong wrote:

> I am having problem with my code which I need to count the number of
> images browsing from a path and displaying in a static text box. Here is
> my codes:
> D = uigetdir('*.jpg');

D will now contain the *name* of the directory

> numberfiles = numel(D);

You are asking for the number of elements in the *name* of the directory.

It isn't really clear what you are wanting to do. Possibly use
uigetfile() with MultiSelect turned on, and test the Filename returned
to see if it is char or not; if it is char then it is a single file
name, and if it is not char then it is a cell array of strings and the
length() of that cell array would be the number of selected files.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us