How to make a curve line through data points on surface 3D (curve line fitting in 3D)
조회 수: 2 (최근 30일)
이전 댓글 표시
Dear everyone,
I have a suface 3D in matlab. I want to build a curve line through data points (A, B, C, D) in this surface. I think this is the curve line fitting of surface. I try to do that but I couldn't obtain result. Please Help me for this.
The code is showed below.
Many thanks,
Best regard.
clear all;
clc;
x1 = [10,11,12,10,11,12,10,11,12,10,11,12];
x2 = [60,60,60,70,70,70,80,80,80,90,90,90];
Profit = [133.355, 151.273, 143.703, 201.625, 218.227, 209.948, 219.271, 246.907, 233.791, 215.890, 246.132, 228.042];
xv = 10:0.1:12;
yv =60:1:90;
[X,Y] = ndgrid(xv, yv);
Z = griddata(x1, x2, Profit, X, Y, 'cubic');
figure
surf(X,Y,Z)
grid on
hold on
A=scatter3(x1(8),x2(8),Profit(8),'filled','MarkerFaceColor', 'y')
B=scatter3(x1(2),x2(2),Profit(2),'filled','MarkerFaceColor', 'y')
C=scatter3(x1(5),x2(5),Profit(5),'filled','MarkerFaceColor', 'y')
D=scatter3(x1(11),x2(11),Profit(11),'filled','MarkerFaceColor', 'y')
xlabel('Скорость, м/с'), ylabel('Грузоподъемность, т'), zlabel('Profit, 10^4*$')
view(-120,47)
댓글 수: 2
Ameer Hamza
2020년 5월 8일
Can you show an example of your expected output? How do you want to draw the curved line?
채택된 답변
추가 답변 (1개)
Sulaymon Eshkabilov
2020년 5월 8일
Hi,
Since you are plotting 3D plot of data, probably you're looking for a surface fit model. Then it is easy to use: cftool and select X, Y, Z and obtain the fit. Here is a sample code - a cubic fit generated by the cftool (Curve Fitting) toolbox.
function [fitresult, gof] = createFit(X, Y, Z)
%CREATEFIT(X,Y,Z)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input : X
% Y Input : Y
% Z Output: Z
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 08-May-2020 16:05:32
%% Fit: 'untitled fit 1'.
[xData, yData, zData] = prepareSurfaceData( X, Y, Z );
% Set up fittype and options.
ft = 'cubicinterp';
% Fit model to data.
[fitresult, gof] = fit( [xData, yData], zData, ft, 'Normalize', 'on' );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, [xData, yData], zData );
legend( h, 'untitled fit 1', 'Z vs. X, Y', 'Location', 'NorthEast' );
% Label axes
xlabel X
ylabel Y
zlabel Z
grid on
Good luck
참고 항목
카테고리
Help Center 및 File Exchange에서 Fit Postprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


