Construct the complete curve from one segment of it

7 views (last 30 days)
I wish to construct the complete curve from one available segment of it. For example, d1(:,2) is the complete curve; how to construct this full curve from one segment of it i.e. d1(130:270,2)? Again if I have two datasets namely complete d1 and a segment of d2 such as d2(130:270,2). Is it possible to construct the complete curve of d2 from its segment d2(130:270,2)??
Please help.

Answers (3)

John D'Errico
John D'Errico on 27 Dec 2022
Edited: John D'Errico on 27 Dec 2022
load d1.mat
x = d1(:,1);
y = d1(:,2);
k = 130:270;
Seriouisly, you want to reconstruct the ENTIRE curve only by knowing the small piece in red?
Sorry, but completely impossible. Anything you would try to do to reconstruct the rest of the curve is a MASSIVE extrapolation. The predictions out there would be virtually random numbers. Extrapolation in general is difficult, and often impossible to do intelligenty. Extrapolate that far out from that little data is literally impossible to do well.
John D'Errico
John D'Errico on 28 Dec 2022
Edited: John D'Errico on 28 Dec 2022
The magic wand would (at least partially) indeed be knowing the complete relationship. But guessing it MIGHT be gaussian or lorentizian is not knowing. Just as in my example, you cannot infer the shape of the entire curve from a small segment of that curve.
And even if you know the basic overall shape, you still cannot easily infer the extrapolated behavior, because all of your numbers are represented as double precision values. That means that tiny changes in the least significant bits of those numbers would be needed to infer the shape of that curve far out along the axis.
So I'm sorry, but no. As much as you want to do this, you cannot do so.
I'm not at all sure what you mean by some sort of piecewise representation. But again, you cannot infer from a small piece what the shape of the whole is.
Perhaps I could suggest the old story about the blind wise men and the elephant? One feels the tail, and decides the elephant is like rope. Another feels the leg, and thinks the elephant is like a tree. Another feels a tusk, or the trunk, or the ear, and each infers something completely different. You cannot infer the complete attributes of a large thing, merely by looking at a small part.
Finally, perhaps you are asking how to use something like a spline, without really understanding what is a spline. And, yes, a spline does allow you to approximate a complete curve using segments. But that does not mean one segment can in any way be extrapolated out to the whole, without using the entire curve to constrauct the spline.
load d1.mat
x = d1(:,1);
y = d1(:,2);
spl = spline(x,y);
So spl is a cubic spline, composed of actually a huge number of tiny segments of cubic polynomials. Each was construtec from the curve I passed into spline. But they were not constructed separately. Only by having the ENTIRE curve to build that spline could the curve be reconstructed. Had I tried to use only the points from a small sub-domain, and then extrapolate it, I would get complete nonsense.

Sign in to comment.

Image Analyst
Image Analyst on 27 Dec 2022
You can assume it's a polynomial, but that data does not fit a polynomial well.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 14;
fileName = 'd1.mat';
s = load(fileName);
x = s.d1(:,1);
y = s.d1(:,2);
k = 130:270;
subplot(2, 1, 1);
plot(x,y,'-b', 'lineWidth', 2);
hold on;
plot(x(k),y(k),'r-', 'LineWidth', 5)
grid on;
title('Original Data', 'fontSize', fontSize)
legend('Full Curve', 'Training Data', 'Location', 'south')
% Assume we have a nth order polynomial.
xTrain = x(k);
yTrain = y(k);
polynomialOrder = 6; % Whatever you want.
coefficients = polyfit(xTrain, yTrain, polynomialOrder)
coefficients = 1×7
-1.67521364003749e-09 2.01447120219391e-07 -9.87020743066138e-06 0.000251820317381273 -0.00352965109727797 0.025856117987483 0.585520506591492
xFit = x;
yFit = polyval(coefficients, xFit);
subplot(2, 1, 2);
plot(xFit, yFit,'r-', 'LineWidth', 2);
grid on;
caption = sprintf('Data fitted to a polynomial of order %d', polynomialOrder);
title(caption, 'fontSize', fontSize)
  1 Comment
Josh on 27 Dec 2022
Edited: Josh on 27 Dec 2022
@Image Analyst Appreciate your kind response, and the predicited curve does not signify the real nature of the original curve.May you try some alternative way or suggest who may help me.

Sign in to comment.

Steven Lord
Steven Lord on 28 Dec 2022
Moved: Image Analyst on 28 Dec 2022
Let's say I give you five points on a curve. Can you tell me what curve I sampled to get those points?
x = -2:2;
y = [0 0 0 0 0];
plot(x, y, 'o')
sampleX = linspace(-2, 2, 100);
Is this this curve? Note that it goes straight through the points represented by x and y.
plot(x, y, 'o', sampleX, zeros(size(sampleX)), '+-')
title("y = 0")
How about this one? It too goes through those points.
plot(x, y, 'o', sampleX, sinpi(sampleX), '+-')
title("y = sin(pi*x)")
Or this one?
y2 = (x(1)-sampleX).*(x(2)-sampleX).*(x(3)-sampleX).*(x(4)-sampleX).*(x(5)-sampleX);
plot(x, y, 'o', sampleX, y2, '+-')
t = sprintf("(%d-x).*", x)
t = "(-2-x).*(-1-x).*(0-x).*(1-x).*(2-x).*"
title("y = " + extractBefore(t, strlength(t)-1))
Without additional information there is no absolutely way to tell which of those curves (or any of an infinite number of other possibilities) is the correct one I sampled to get those five points.
So what additional information do you have about your curve beyond the raw data points?
Image Analyst
Image Analyst on 28 Dec 2022
No, it is not possible to accurately guess what's outside the training range if you make no assumptions. Three of us have told you that now. It doesn't matter that you know what's there -- if that is not used in the training and prediction then it is of absolutely no help, except to let you know that whatever you came up with is wrong. I mean you could have hundreds of "true" plots outside of the training region, and if all you have is the training region, how could you possibly know which one was the "true" one? You can't. It's impossible.
But your signal looks like some kind of smooth function that follows some mathematical formula. If you knew that formula, even the form of it, not necessarily the coefficients of the parameters, then we could use something like fitnlm to find the coefficients and the best fitting formula.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!