For Programmers: Free Programming Magazines  


Home > Archive > Matlab > August 2007 > textscan









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author textscan
Corinna Schmitt

2007-08-30, 4:29 am

Hallo,

I want to read a tab-delimited txt-file. At the moment I
realisied it with textread. It works. Can any one show me
how it would work with textscan? I cannot realize it with
the Matlab-HELP. The original txt-file comes from exel and
consist of 3 rows and 5 columns.
The aim is to have the input in one variable from where I
than extract every information I need.

My solution with txtread:

[patient1, patient2, patient3, patient4, patient5] = ...
textread(source,'%s%s%s%s%s',3, 'delimiter', '\t');

In this case the bad thing is that I need to specifiy the
wright number of variables in the first breaket and
afterwards I have 5 for-loops to handle the informations on
into one variable - overviewTable=cell
(factorsPerPatient,numberOfPatients) - where the column i
stand for the patient i.

The inputfile looks like this:
1 1 2 1 2
23 4 5 23 5
6 7 8 9 10

A new line seems to be realized with /n.

Has anyone an idea?

Corinna
Corinna Schmitt

2007-08-30, 4:29 am

Sorry,
I forgot to say that factorsPerPatient=3 and
numberOfPatients=5

That means for the command:
overviewTable=cell(3,5);

CU Corinna
Titus

2007-08-30, 8:15 am


"Corinna Schmitt" <csc@mathworks.com> schrieb im Newsbeitrag
news:fb62cl$ipo$1@fred.mathworks.com...
> Hallo,
>
> I want to read a tab-delimited txt-file. At the moment I
> realisied it with textread. It works. Can any one show me
> how it would work with textscan? I cannot realize it with
> the Matlab-HELP. The original txt-file comes from exel and
> consist of 3 rows and 5 columns.
> The aim is to have the input in one variable from where I
> than extract every information I need.
>
> My solution with txtread:
>
> [patient1, patient2, patient3, patient4, patient5] = ...
> textread(source,'%s%s%s%s%s',3, 'delimiter', '\t');
>
> In this case the bad thing is that I need to specifiy the
> wright number of variables in the first breaket and
> afterwards I have 5 for-loops to handle the informations on
> into one variable - overviewTable=cell
> (factorsPerPatient,numberOfPatients) - where the column i
> stand for the patient i.
>
> The inputfile looks like this:
> 1 1 2 1 2
> 23 4 5 23 5
> 6 7 8 9 10
>
> A new line seems to be realized with /n.
>
> Has anyone an idea?
>
> Corinna




Hi Corinna,

in this case, things get somewhat easier: just use load to read your data:

patientData = load(source, '-ascii');

Titus



Titus

2007-08-30, 8:15 am


"Titus" <titus.edelhofer@mathworks.de> schrieb im Newsbeitrag
news:fb62pa$oai$1@fred.mathworks.com...
>
> "Corinna Schmitt" <csc@mathworks.com> schrieb im Newsbeitrag
> news:fb62cl$ipo$1@fred.mathworks.com...
>
>
>
> Hi Corinna,
>
> in this case, things get somewhat easier: just use load to read your data:
>
> patientData = load(source, '-ascii');
>
> Titus
>
>
>



just forgot to ask: if the file contains numbers, why do you read strings?
my solution from above works only for numbers ...

Titus


Corinna Schmitt

2007-08-30, 8:15 am

Hallo Titus,

> just forgot to ask: if the file contains numbers, why do

you read strings?

My program should be integrate in a database where I will
get the input file from later. at the moment I must work
with handmade files and so I do not know if they are
strings or numbers.

> my solution from above works only for numbers ...


Another friend gave me another solution. The solution is:

xyz = repmat('%s', 1, 5) ;
fid = fopen(source);
inputData = textscan(fid, xyz);
fclose(fid);

it works!

Thanks for you ideas,
Corinna
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com