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:
How can i retrieve a function?

Subject: How can i retrieve a function?

From: Covadonga dubrovnic

Date: 23 Mar, 2010 11:08:05

Message: 1 of 6

How can i retrieve a function, possibly in a periodic form, from a figure that was made by using the cubic spline interpolation on a set of datas?

Subject: How can i retrieve a function?

From: Covadonga dubrovnic

Date: 23 Mar, 2010 12:08:07

Message: 2 of 6

"Covadonga dubrovnic" <covadonga.project@gmail.com> wrote in message <hoa7el$jqo$1@fred.mathworks.com>...
> How can i retrieve a function, possibly in a periodic form, from a figure that was made by using the cubic spline interpolation on a set of datas?


I thought of helping you out with this problem by including the code i used to generate my figure.
[code]

clear
close all
clc

x = 0:23; %cam rotation angle%
y = [15 15 13.5 9.5 4 0 -3 -6.5 -9.5 -12 -13.5 -15 -15 -13 -11 -9 -6 -3.5 0.5 4 9 13 15 15];
%piston height in mm%
cs = spline(x,[0 y 0]);
xx = linspace(0,23,100000);
figure (1);
plot(x,y,'o',xx,ppval(cs,xx),'-');

[/code]

Subject: How can i retrieve a function?

From: Sadik

Date: 23 Mar, 2010 12:18:06

Message: 3 of 6

Hi Covadonga,

This should help you:

http://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/

Best.

Subject: How can i retrieve a function?

From: Walter Roberson

Date: 23 Mar, 2010 12:22:38

Message: 4 of 6

Covadonga dubrovnic wrote:
> "Covadonga dubrovnic" <covadonga.project@gmail.com> wrote in message
> <hoa7el$jqo$1@fred.mathworks.com>...
>> How can i retrieve a function, possibly in a periodic form, from a
>> figure that was made by using the cubic spline interpolation on a set
>> of datas?
>
>
> I thought of helping you out with this problem by including the code i
> used to generate my figure.
> [code]
>
> clear
> close all
> clc
>
> x = 0:23; %cam rotation angle%
> y = [15 15 13.5 9.5 4 0 -3 -6.5 -9.5 -12 -13.5 -15 -15 -13 -11 -9 -6
> -3.5 0.5 4 9 13 15 15];
> %piston height in mm%
> cs = spline(x,[0 y 0]);
> xx = linspace(0,23,100000);
> figure (1);
> plot(x,y,'o',xx,ppval(cs,xx),'-');
>
> [/code]

Could you clarify which function you are attempting to recover? Is the
goal to examine the figure and work backwards from there to the set of x
and y values that were used to create the cubic spline? Or is the goal
to recover the cubic spline coefficients? Or is the goal to try to
figure out from the fitted spline what the original function that y
samples is?

If you are trying to determine the original function that y samples,
then you cannot do that, not unless you can place constraints as to what
kind of functions might reasonably be in effect, and not unless you
define a mechanism for deciding which of several candidates is the
"real" function. Which is not always an easy thing to do: there is
always a polynomial that fits the data perfectly, but the "real"
function might instead be (e.g.) a sine wave that has a small bit of
measurement error involved. You would need to define some kind of
preference hierarchy, where if the fitting error is too large then you
move to the next (less preferable) function form.

Subject: How can i retrieve a function?

From: Covadonga dubrovnic

Date: 23 Mar, 2010 12:43:38

Message: 5 of 6

Walter Roberson <roberson@hushmail.com> wrote in message <hoabqf$bmg$1@canopus.cc.umanitoba.ca>...
> Covadonga dubrovnic wrote:
> > "Covadonga dubrovnic" <covadonga.project@gmail.com> wrote in message
> > <hoa7el$jqo$1@fred.mathworks.com>...
> >> How can i retrieve a function, possibly in a periodic form, from a
> >> figure that was made by using the cubic spline interpolation on a set
> >> of datas?
> >
> >
> > I thought of helping you out with this problem by including the code i
> > used to generate my figure.
> > [code]
> >
> > clear
> > close all
> > clc
> >
> > x = 0:23; %cam rotation angle%
> > y = [15 15 13.5 9.5 4 0 -3 -6.5 -9.5 -12 -13.5 -15 -15 -13 -11 -9 -6
> > -3.5 0.5 4 9 13 15 15];
> > %piston height in mm%
> > cs = spline(x,[0 y 0]);
> > xx = linspace(0,23,100000);
> > figure (1);
> > plot(x,y,'o',xx,ppval(cs,xx),'-');
> >
> > [/code]
>
> Could you clarify which function you are attempting to recover? Is the
> goal to examine the figure and work backwards from there to the set of x
> and y values that were used to create the cubic spline? Or is the goal
> to recover the cubic spline coefficients? Or is the goal to try to
> figure out from the fitted spline what the original function that y
> samples is?
>
> If you are trying to determine the original function that y samples,
> then you cannot do that, not unless you can place constraints as to what
> kind of functions might reasonably be in effect, and not unless you
> define a mechanism for deciding which of several candidates is the
> "real" function. Which is not always an easy thing to do: there is
> always a polynomial that fits the data perfectly, but the "real"
> function might instead be (e.g.) a sine wave that has a small bit of
> measurement error involved. You would need to define some kind of
> preference hierarchy, where if the fitting error is too large then you
> move to the next (less preferable) function form.

Thank you very much indeed, your explanation was very helpful, i'll try to explain myself better.
My goal, as you already figured out, is to recover the cubic spline coefficients. I know that there are several functions that could fit in the curve i obtained, but my problem, before having to decide wich solution is the best, is to obtain at least ONE or two possible solutions.
Btw the hierarchy i'll apply will not be too strict because it's a mechanical problem, therefore heavy approximation is a common practice, in particular during the first steps of the design

Subject: How can i retrieve a function?

From: Steven Lord

Date: 23 Mar, 2010 13:42:14

Message: 6 of 6


"Covadonga dubrovnic" <covadonga.project@gmail.com> wrote in message
news:hoad1q$h41$1@fred.mathworks.com...
> Walter Roberson <roberson@hushmail.com> wrote in message
> <hoabqf$bmg$1@canopus.cc.umanitoba.ca>...
>> Covadonga dubrovnic wrote:
>> > "Covadonga dubrovnic" <covadonga.project@gmail.com> wrote in message
>> > <hoa7el$jqo$1@fred.mathworks.com>...
>> >> How can i retrieve a function, possibly in a periodic form, from a
>> >> figure that was made by using the cubic spline interpolation on a set
>> >> of datas?

*snip*

> Thank you very much indeed, your explanation was very helpful, i'll try to
> explain myself better. My goal, as you already figured out, is to recover
> the cubic spline coefficients. I know that there are several functions
> that could fit in the curve i obtained, but my problem, before having to
> decide wich solution is the best, is to obtain at least ONE or two
> possible solutions.
> Btw the hierarchy i'll apply will not be too strict because it's a
> mechanical problem, therefore heavy approximation is a common practice, in
> particular during the first steps of the design

If you still have the output of your SPLINE call, it contains the
coefficients. Look at cs -- the cs.coefs field is what you're looking for.
One caveat if you're going to evaluate this function directly; the function
represented by the coefficients is a function of (x-leftbreak) not of x, so
either adjust your x data appropriately or call PPVAL (which handles that
automatically.)

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

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