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:
line and curve intersection

Subject: line and curve intersection

From: dwi

Date: 21 Oct, 2012 12:34:08

Message: 1 of 2

I have this part of a code:
x=randn(1000,1);
plot(x);
for i=1:length(x)
y(i)=0;
end
hold on
plot (y);

How can I find how many times the line y=0 intersects the curve formed by the data in x? I tried another loop where I check whether x=y then index=index+1 but it always returns index=0. ANy ideas?

Subject: line and curve intersection

From: dpb

Date: 21 Oct, 2012 14:02:37

Message: 2 of 2

On 10/21/2012 7:34 AM, dwi wrote:
> I have this part of a code:
> x=randn(1000,1);
> plot(x);

> for i=1:length(x)
> y(i)=0;
> end

y=zeros(size(x));

> hold on
> plot (y);

doc line


> How can I find how many times the line y=0 intersects the curve formed
> by the data in x? ...

ncross=sum(diff(sign(x))~=0);

--

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