Thread Subject: How to read data from a file????

Subject: How to read data from a file????

From: jacob lalaounis

Date: 25 Nov, 2009 17:03:19

Message: 1 of 2

Helllo,

I want to read a file that has data like this.I want to make an array from the third colum to get the numbers and in the space to apply zero and where the * is to apply -1. I try to textread but it is impossible to manage the cell array.

  5) 3 368ms
  6) 1
  7) 6
  8) 1
  9) 4
 10) 1 *
 11) 6 *
 12) 1 *
 13) 2
 14) 1
 15) 6 410ms

For example
[C,position] = textscan(fed, '%4s %d %q','delimiter','\t')

if(C{1,3}(1:300)=='*')

this if doesnt work because C is a cell array

Help

Thanks alot in advance

Subject: How to read data from a file????

From: dpb

Date: 26 Nov, 2009 00:47:48

Message: 2 of 2

jacob lalaounis wrote:
> Helllo,
>
> I want to read a file that has data like this.I want to make an array
> from the third colum to get the numbers and in the space to apply zero
> and where the * is to apply -1. I try to textread but it is impossible
> to manage the cell array.
>
> 5) 3 368ms
> 6) 1
> 7) 6
> 8) 1
> 9) 4
> 10) 1 *
> 11) 6 *
> 12) 1 *
> 13) 2
> 14) 1
> 15) 6 410ms
>
> For example
> [C,position] = textscan(fed, '%4s %d %q','delimiter','\t')
>
> if(C{1,3}(1:300)=='*')
>
> this if doesnt work because C is a cell array
...

Not sure I know _exactly_ what your request is and it took a couple
tries, but see if can salt following to suit...

 >> [C,p] = textread('test.dat', '%*4s %d %q');
 >> p(strcmp(p,'*'))={'-1'};
 >> p(strcmp(p,''))={'0'};
 >> p
p =
     '368ms'
     '0'
     '0'
     '0'
     '0'
     '-1'
     '-1'
     '-1'
     '0'
     '0'
     '410ms'
 >>

--

Tags for this Thread

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.

rssFeed for this Thread

Contact us at files@mathworks.com