extract all points from curves

조회 수: 6 (최근 30일)
Salwa Ben Mbarek
Salwa Ben Mbarek 2021년 5월 11일
답변: Salwa Ben Mbarek 2021년 5월 14일
Hello,
In the code below : Is there's any chance to have the coordinates of intermediate points (for example to have "y" when x=1.5 ) ...I just want to have all coordinates from curves, and not only natural numbers like x coordinates and y coordinates.
I've tried with "findobj" but It did not work. Thank you for your help.
x= [1,2,3,4,5,6,7,8,9,10]
y= [1,2,3,4,5,6,7,8,9,10]
figure
plot(x,y)
  댓글 수: 1
Adam Danz
Adam Danz 2021년 5월 11일
> I just want to have all coordinates from curves
There are an infinite number of points on a curve. Even if you limit the interval to the lowest possible floating point representation, your system will likely reach memory capacity. For values 1 to 10, there would be something like 4*10^16 values.
Your options are to interpolate or fit the curve, both of which are demonstrated in the answers below.
(10-1)/eps
ans = 4.0532e+16

댓글을 달려면 로그인하십시오.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2021년 5월 11일
x= [1,2,3,4,5,6,7,8,9,10]
y= [1,2,3,4,5,6,7,8,9,10]
in=[1.2,2.3,3.5]
out=interp1(x,y,in)

추가 답변 (2개)

Image Analyst
Image Analyst 2021년 5월 11일
Try this:
% Create sample data.
x = [1,2,3,4,5,6,7,8,9,10]
y = [1,2,3,4,5,6,7,8,9,10]
% Add some noise to make the data "wavy".
y = y + rand(1, length(y));
markerSize = 20;
plot(x, y, 'bo', 'MarkerSize', markerSize);
grid on;
hold on;
xlabel('x', 'FontSize', 20);
ylabel('y', 'FontSize', 20);
% Define intermediate values.
desiredX = min(x) : 0.333333333 : max(x);
% Do a spline fit, which can follow curves better than interp with lines.
yFit = spline(x, y, desiredX);
plot(desiredX, yFit, 'r.', 'MarkerSize', markerSize);
legend('Original', 'Fit', 'Location', 'northwest');

Salwa Ben Mbarek
Salwa Ben Mbarek 2021년 5월 14일
Thanks to all of you for your explanations . It works !

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by