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:
Omitting certain lines with 'textscan'

Subject: Omitting certain lines with 'textscan'

From: Ryan Utz

Date: 23 Nov, 2008 19:32:01

Message: 1 of 6

Hi all,

I'm trying to import a very basic data set that looks like this:

year month day hour flow
1992 2 13 6 18.3

Sometimes, however, when the data are erroneous the final field (flow) is listed as a negative number. I'd like to just omit any and all data when this is the case, in other words, I don't even want the dates for erroneous data to be imported. Is there a clean way in 'textscan' to specify when to ignore a particular line when it involves just one field? If not, anyone have any post-import ideas?

Thanks,
Ryan

Subject: Omitting certain lines with 'textscan'

From: NZTideMan

Date: 23 Nov, 2008 20:06:06

Message: 2 of 6

On Nov 24, 8:32=A0am, "Ryan Utz" <r...@al.umces.edu> wrote:
> Hi all,
>
> I'm trying to import a very basic data set that looks like this:
>
> year month day hour flow
> 1992 2 13 6 18.3
>
> Sometimes, however, when the data are erroneous the final field (flow) is=
 listed as a negative number. I'd like to just omit any and all data when t=
his is the case, in other words, I don't even want the dates for erroneous =
data to be imported. Is there a clean way in 'textscan' to specify when to =
ignore a particular line when it involves just one field? If not, anyone ha=
ve any post-import ideas?
>
> Thanks,
> Ryan

Think about it.
How would textscan (or any routine) know if the number was negative
unless it read it in?
The best way is to read everything in, then post process the data by
finding the addresses of the negative flows:
indx=3DQ<0;
or
indx=3Dfind(Q<0);
Then you can eliminate those rows:
Q(indx)=3D[];
year(indx)=3D[];
etc

Subject: Omitting certain lines with 'textscan'

From: Walter Roberson

Date: 23 Nov, 2008 20:07:10

Message: 3 of 6

Ryan Utz wrote:
> Sometimes, however, when the data are erroneous the final field (flow) is listed as
> a negative number. I'd like to just omit any and all data when this is the case,
> in other words, I don't even want the dates for erroneous data to be imported. Is there
> a clean way in 'textscan' to specify when to ignore a particular line when it involves
> just one field?

Sorry, no.

> If not, anyone have any post-import ideas?

A(A(:,end) < 0),:) = [];

The above will delete all rows of A in which the last column is less than 0.


--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: Omitting certain lines with 'textscan'

From: Andres

Date: 23 Nov, 2008 20:09:02

Message: 4 of 6

"Ryan Utz" <rutz@al.umces.edu> wrote in message <ggcb3h$k5k$1@fred.mathworks.com>...
> Hi all,
>
> I'm trying to import a very basic data set that looks like this:
>
> year month day hour flow
> 1992 2 13 6 18.3
>
> Sometimes, however, when the data are erroneous the final field (flow) is listed as a negative number. I'd like to just omit any and all data when this is the case, in other words, I don't even want the dates for erroneous data to be imported. Is there a clean way in 'textscan' to specify when to ignore a particular line when it involves just one field? If not, anyone have any post-import ideas?

It looks much easier to me to follow the post-import route...
as an example:
a = [1 2 3
     4 5 -6
     7 8 9];
isOk = a(:,end)>=0;
b = a(isOk,:);

Subject: Omitting certain lines with 'textscan'

From: Andres

Date: 23 Nov, 2008 20:16:01

Message: 5 of 6

Hey, why is everbody repying at the same instant?
Ok, I was the last, I'll by a round and log out.
Bye
A.

Subject: Omitting certain lines with 'textscan'

From: Ryan Utz

Date: 23 Nov, 2008 23:27:02

Message: 6 of 6

Thanks everyone-this solution works great! This newsgroup is a life-saver.

Ryan

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