## Breaking a 2d cloud of data points into straight line segments

## Breaking a 2d cloud of data points into straight line segments

(OP)

I recently found a couple of ways of doing this. They are not automatic, and i suspect they need some judgement in their use.

The first is from Matlab https://www.mathworks.com/help/signal/ref/findchan...

and the second is the very neat SLM curve fitting toolbox https://www.mathworks.com/matlabcentral/fileexchan...

When i get matlab back then I'll be using these.

The first is from Matlab https://www.mathworks.com/help/signal/ref/findchan...

and the second is the very neat SLM curve fitting toolbox https://www.mathworks.com/matlabcentral/fileexchan...

When i get matlab back then I'll be using these.

Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

## RE: Breaking a 2d cloud of data points into straight line segments

## CODE -->

The black line is an eyeballed set of knots for the blue data. The circles are 11 year moving averages and the orange line is just a linear regression.

I looked at two built in functions. 'splinefit' tries to equalise the segment lengths. 'polyfit' doesn't guarantee that the lines are contiguous at the knots.

Cheers

Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

## RE: Breaking a 2d cloud of data points into straight line segments

x=1:100;

y(1:25) = 0+rand(25,1);

y(26:50) = 1+rand(25,1);

y(51:75) = 2+rand(25,1);

y(76:100)= -1+rand(25,1);

figure

plot(x,y,'r.')

hold on

sp3=spap2(3,2,x,y) % 3 joints, 1st order( use a 2 for 1st order )

fnplt(sp3,'m')

## RE: Breaking a 2d cloud of data points into straight line segments

Can you share that data? I've got some spare time at the moment.

TTFN (ta ta for now)

I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg

FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm

## RE: Breaking a 2d cloud of data points into straight line segments

## RE: Breaking a 2d cloud of data points into straight line segments

Cheers

Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

## RE: Breaking a 2d cloud of data points into straight line segments

Cheers

Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

## RE: Breaking a 2d cloud of data points into straight line segments

Cheers

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

Greg Locock

## RE: Breaking a 2d cloud of data points into straight line segments

TTFN (ta ta for now)

I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg

FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm

## RE: Breaking a 2d cloud of data points into straight line segments

Cheers

Greg Locock

## RE: Breaking a 2d cloud of data points into straight line segments

Greg Locock

## RE: Breaking a 2d cloud of data points into straight line segments

## RE: Breaking a 2d cloud of data points into straight line segments

## RE: Breaking a 2d cloud of data points into straight line segments

TTFN (ta ta for now)

I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg

FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm