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:
changes in a column

Subject: changes in a column

From: Jessica

Date: 9 Oct, 2008 13:53:11

Message: 1 of 2

Hi,

I have columns that looks like this:

2
2
2
2
NaN
NaN
1
1
1
1
NaN
1
1
NaN
2
2
2
2
NaN
NaN
NaN
NaN
1


I am trying to determine how many times within the column that the value switches from 1 to 2 (or 2 to 1). Thus, in this example, it switches 3 times (first from 2 --> 1, then from 1 --> 2, and finally back from 2 --> 1).

Is there a command I can use to determine this?

Thanks!

Subject: changes in a column

From: Walter Roberson

Date: 9 Oct, 2008 16:07:50

Message: 2 of 2

Jessica wrote:
> I have columns that looks like this:
 
> 2
> 2
> 2
> 2
> NaN
> NaN
> 1
> 1
> 1
> 1
> NaN
> 1
> 1
> NaN
> 2
> 2
> 2
> 2
> NaN
> NaN
> NaN
> NaN
> 1
 
> I am trying to determine how many times within the column that the value switches from 1 to 2
> (or 2 to 1). Thus, in this example, it switches 3 times (first from 2 --> 1, then from 1 --> 2,
> and finally back from 2 --> 1).

Where Col is the column vector:

sum(abs(diff(Col(~isnan(Col)))))

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