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:
importdata

Subject: importdata

From: Johan

Date: 31 Oct, 2012 12:18:08

Message: 1 of 5

Hi Guys,

I got a problem with a .txt file I wanna import to my matlab workspace.

I already used the operation "importdata" to read the file, but I don't want matlab to create a vector, where all my data is stored in one cell, seperated by a comma. Of course I know, that matlab needs to know, what kind of information it's importing and how the data is saved, respectively serperated from each other.
So I thought the next step must be, to put a delimiter in my operation, in this specific case (','), but matlab still creates the vector and not what i did expect, a matrix.
Do I have to give matlab the information about the size of my matrix or is there something else missing.

If someone got a hint for me, how I easily can import text files and how to use the delimiters right, I would really be grateful.

Thank you!

Johan

Subject: importdata

From: Ilham Hardy

Date: 31 Oct, 2012 15:09:09

Message: 2 of 5

"Johan" wrote in message <k6r4u0$akl$1@newscl01ah.mathworks.com>...
> Hi Guys,
>
> I got a problem with a .txt file I wanna import to my matlab workspace.
>
> I already used the operation "importdata" to read the file, but I don't want matlab to create a vector, where all my data is stored in one cell, seperated by a comma. Of course I know, that matlab needs to know, what kind of information it's importing and how the data is saved, respectively serperated from each other.
> So I thought the next step must be, to put a delimiter in my operation, in this specific case (','), but matlab still creates the vector and not what i did expect, a matrix.
> Do I have to give matlab the information about the size of my matrix or is there something else missing.
>
> If someone got a hint for me, how I easily can import text files and how to use the delimiters right, I would really be grateful.
>
> Thank you!
>
> Johan


If your data is a .csv file, you can try use 'csvread' function..
Eitherway, low-level data reading function such as textscan or regexp gives more flexibility..

If you can put 'the code' you've made in here, i'm sure more people will be more willing to help..

HTH,
IH

Subject: importdata

From: Johan

Date: 9 Nov, 2012 08:52:06

Message: 3 of 5

"Ilham Hardy" wrote in message <k6reul$kuu$1@newscl01ah.mathworks.com>...
> "Johan" wrote in message <k6r4u0$akl$1@newscl01ah.mathworks.com>...
> > Hi Guys,
> >
> > I got a problem with a .txt file I wanna import to my matlab workspace.
> >
> > I already used the operation "importdata" to read the file, but I don't want matlab to create a vector, where all my data is stored in one cell, seperated by a comma. Of course I know, that matlab needs to know, what kind of information it's importing and how the data is saved, respectively serperated from each other.
> > So I thought the next step must be, to put a delimiter in my operation, in this specific case (','), but matlab still creates the vector and not what i did expect, a matrix.
> > Do I have to give matlab the information about the size of my matrix or is there something else missing.
> >
> > If someone got a hint for me, how I easily can import text files and how to use the delimiters right, I would really be grateful.
> >
> > Thank you!
> >
> > Johan
>
>
> If your data is a .csv file, you can try use 'csvread' function..
> Eitherway, low-level data reading function such as textscan or regexp gives more flexibility..
>
> If you can put 'the code' you've made in here, i'm sure more people will be more willing to help..
>
> HTH,
> IH

Hi,

I dont have a cod, cause what i did, was to use textscan and thats all. My Problem ist that i cant figure out, how to split my data, to get it in a matrix. As I wrote, i dont know how to use 'textscan' or 'importdata' right. So if you do have an idea how to solve my problem, it would be great.

Example:

date; station_number; temperature; Power;
120114; 2456; 13; 98,21
120115; 2456; 16; 124,09
120116; 2456; 15; 111,95
120117; .....

Thats what my textfile look like, now i tried 'importdata()' but i only get a vector including all my data in one cell. Certainly I do know, that matlab cant split my data, cause the information about my delimiter is missing, but when I try it like this
importdata('textdata.txt', ';');
matlab still creates the same results.
My current solution is to copy my textdata and insert it into microsoft excel, where i easily can split my data. Then I can use the matlab operation
xlsread('textdata.xlsx');
but thats not what i really wanted.

What I am just trying, is to save my txt file as csv, and use 'csvread()' from matlab, as u suggested, perhaps this will work...

Ty

Subject: importdata

From: Nasser M. Abbasi

Date: 9 Nov, 2012 08:57:28

Message: 4 of 5


> date; station_number; temperature; Power;
> 120114; 2456; 13; 98,21
> 120115; 2456; 16; 124,09
> 120116; 2456; 15; 111,95
> 120117; .....
>
> Thats what my textfile look like,

Ok, so what are those numbers at the end of the lines?

98,21
124,09
111,95

Are you using "," in place of decimal point? and if so, why?

--Nasser

Subject: importdata

From: Johan

Date: 9 Nov, 2012 09:47:17

Message: 5 of 5

"Nasser M. Abbasi" <nma@12000.org> wrote in message <k7ighv$tih$1@speranza.aioe.org>...
>
> > date; station_number; temperature; Power;
> > 120114; 2456; 13; 98,21
> > 120115; 2456; 16; 124,09
> > 120116; 2456; 15; 111,95
> > 120117; .....
> >
> > Thats what my textfile look like,
>
> Ok, so what are those numbers at the end of the lines?
>
> 98,21
> 124,09
> 111,95
>
> Are you using "," in place of decimal point? and if so, why?
>
> --Nasser

Hi,

I only created some random values to make sure, you understand how my datafile look like.
Normally the last numbers should represent the golbal radiation on a photovoltaik system on different days. Since the data is free to download, heres the link

http://www.dwd.de/bvbw/appmanager/bvbw/dwdwwwDesktop?_nfpb=true&_pageLabel=_dwdwww_klima_umwelt_klimadaten_deutschland&T82002gsbDocumentPath=Navigation%2FOeffentlichkeit%2FKlima__Umwelt%2FKlimadaten%2Fkldaten__kostenfrei%2Fausgabe__tageswerte__node.html%3F__nnn%3Dtrue

Cause it is a german homepage I think its normal to seperate values with a decimal comma.

I hope this will help.

Johan

Tags for 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