How to make a curve line through data points on surface 3D (curve line fitting in 3D)
6 次查看(过去 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 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!