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:
reading data files

Subject: reading data files

From: Marcio Barbalho

Date: 5 Mar, 2010 09:51:26

Message: 1 of 5

Dear friends...

How are you?

I am trying to develop a very simple code to read data (file.dat or file.xls) and then create a mat-file. The dat or xls file will be read by the command /uigetfile/

[filename,filepath]=uigetfile()

that means I cant predict the file's name.

For example:

my data file is 'mydata.xls' and I want to save its content into a mat-file whose name is the very same 'mydata.mat'.

How would you do that?

Many thanks

Subject: reading data files

From: Justus Skorps

Date: 5 Mar, 2010 10:03:01

Message: 2 of 5

> The dat or xls file will be read by the command /uigetfile/
>
> [filename,filepath]=uigetfile()

No...that only gives you the filename and path, it does not read the
file

> my data file is 'mydata.xls' and I want to save its content into a mat-file whose name is the very same 'mydata.mat'.
>
> How would you do that?

RTFM
doc xlsread
doc load
doc save

Subject: reading data files

From: Pekka Kumpulainen

Date: 5 Mar, 2010 10:04:15

Message: 3 of 5

"Marcio Barbalho" <marciobarbalho@yahoo.com> wrote in message <hmqk6u$ier$1@fred.mathworks.com>...
> Dear friends...
>
> How are you?
>
> I am trying to develop a very simple code to read data (file.dat or file.xls) and then create a mat-file. The dat or xls file will be read by the command /uigetfile/
>
> [filename,filepath]=uigetfile()
>
> that means I cant predict the file's name.
>
> For example:
>
> my data file is 'mydata.xls' and I want to save its content into a mat-file whose name is the very same 'mydata.mat'.
>
> How would you do that?
>
> Many thanks

Why would you need to predict the filename?
uigetfile gives it to you in output variable filename and filepath in the example line you have.
doc uigetfile
doc save
You might also want to use
fileparts
fullfile

Subject: reading data files

From: Marcio Barbalho

Date: 6 Mar, 2010 01:35:24

Message: 4 of 5

> You might also want to use
> fileparts
> fullfile

'fileparts' is the command I am looking for. Thank you.

My question now is... once MATLAB knows the file's name. How do I have MATLAB to create an M-file whose name is the name of the file just read?

Example:

/mydata.dat/ will give /mydata.mat/

Many thanks

Subject: reading data files

From: Walter Roberson

Date: 6 Mar, 2010 05:05:13

Message: 5 of 5

Marcio Barbalho wrote:
>> You might also want to use
>> fileparts
>> fullfile
>
> 'fileparts' is the command I am looking for. Thank you.
>
> My question now is... once MATLAB knows the file's name. How do I have
> MATLAB to create an M-file whose name is the name of the file just read?
>
> Example:
>
> /mydata.dat/ will give /mydata.mat/

If the name returned by fileparts includes the extension, then take the
extension output, find its length, remove that many characters from the
end of the name, and append the mat extension you want. Or if the name
does not include the extension, then use fullfile to put together a name
from the parts you got, except using the mat extension instead of
whatever extension was returned by fileparts .

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