Thread Subject: Importing files with similar name

Subject: Importing files with similar name

From: Nuno Loureiro

Date: 20 Nov, 2009 10:38:01

Message: 1 of 4

Hi,

I am trying to read some images on matlab and convert them to matrices. The problem is I have a lot of images to convert and all of them have a similar name:

c=imread('/Users/nl/Desktop/Videos09/GroupA/Video/images/image-001','JPG');
c=imread('/Users/nl/Desktop/Videos09/GroupA/Video/images/image-002','JPG');
... and so on.

The only thing that changes is the last character. Is it possible to do a for changing only the last character of the filename so that I can do this automatically?

Regards,
Nuno

Subject: Importing files with similar name

From: ImageAnalyst

Date: 20 Nov, 2009 11:13:57

Message: 2 of 4

On Nov 20, 5:38 am, "Nuno Loureiro" <phi...@gmail.com> wrote:
> Hi,
>
> I am trying to read some images on matlab and convert them to matrices. The problem is I have a lot of images to convert and all of them have a similar name:
>
> c=imread('/Users/nl/Desktop/Videos09/GroupA/Video/images/image-001','JPG');
> c=imread('/Users/nl/Desktop/Videos09/GroupA/Video/images/image-002','JPG');
> ... and so on.
>
> The only thing that changes is the last character. Is it possible to do a for changing only the last character of the filename so that I can do this automatically?
>
> Regards,
> Nuno

---------------------------------------------------------------------------------------------------------
See section 4.12 of the FAQ:
http://matlabwiki.mathworks.com/MATLAB_FAQ

In short, you use the sprintf() function to build up your filename.

Subject: Importing files with similar name

From: Jan Simon

Date: 20 Nov, 2009 11:15:11

Message: 3 of 4

Dear Nuno!

> I am trying to read some images on matlab and convert them to matrices. The problem is I have a lot of images to convert and all of them have a similar name:
>
> c=imread('/Users/nl/Desktop/Videos09/GroupA/Video/images/image-001','JPG');
> c=imread('/Users/nl/Desktop/Videos09/GroupA/Video/images/image-002','JPG');
> ... and so on.
>
> The only thing that changes is the last character. Is it possible to do a for changing only the last character of the filename so that I can do this automatically?

Yes:

Format = '/Users/nl/Desktop/Videos09/GroupA/Video/images/image-%03d.JPG';

for Num = 1:10 % Arbitrary end...
  File = sprintf(Format, Num);
  disp(File);
  c = imread(File);
  ... insert the calculations here
end

Kind regards, Jan

Subject: Importing files with similar name

From: Nuno Loureiro

Date: 23 Nov, 2009 08:50:12

Message: 4 of 4

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <he5tnv$6ce$1@fred.mathworks.com>...
> Dear Nuno!
>
> > I am trying to read some images on matlab and convert them to matrices. The problem is I have a lot of images to convert and all of them have a similar name:
> >
> > c=imread('/Users/nl/Desktop/Videos09/GroupA/Video/images/image-001','JPG');
> > c=imread('/Users/nl/Desktop/Videos09/GroupA/Video/images/image-002','JPG');
> > ... and so on.
> >
> > The only thing that changes is the last character. Is it possible to do a for changing only the last character of the filename so that I can do this automatically?
>
> Yes:
>
> Format = '/Users/nl/Desktop/Videos09/GroupA/Video/images/image-%03d.JPG';
>
> for Num = 1:10 % Arbitrary end...
> File = sprintf(Format, Num);
> disp(File);
> c = imread(File);
> ... insert the calculations here
> end
>
> Kind regards, Jan

Thank you! It worked =)

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
files with simi... Nuno Loureiro 20 Nov, 2009 05:39:05
rssFeed for this Thread

Contact us at files@mathworks.com