I'm not really sure what you want to achieve here, but if you have X and Y data and want to do a linear fit, then you can construct a line, but if you have a 3D data, then you can construct a plane to be a linear fit in case
Z = function (X,Y).
This is a small example how to construct plane as a result of linear square fit method:
clear; clc; close all
% Input random data
X = randi(10,1,10); % Replace x1, x2, ..., x10 with the actual x values
Y = randi(10,1,10); % Replace y1, y2, ..., y10 with the actual y values
Z = randi(5,1,10); % Replace z1, z2, ..., z10 with the actual z values
% Perform least squares fit
A = [X(:), Y(:), ones(10, 1)];
coefficients = lsqlin([X(:), Y(:), ones(10, 1)],Z(:))
% Extract the calculated parameters
a = coefficients(1); b = coefficients(2); c = coefficients(3);
% Generate points as a mesh grid
x_data = linspace(min(X), max(X), 100);
y_data = linspace(min(Y), max(Y), 100);
[X_data, Y_data] = meshgrid(x_data, y_data);
Z_line = a*X_data + b*Y_data + c;
% Plot the data points and the line
scatter3(X, Y, Z, 50, 'filled', 'MarkerFaceColor', 'b');
hold on;
mesh(X_data, Y_data, Z_line, 'EdgeColor', 'r');
xlabel('X'); ylabel('Y'); zlabel('Z'); zlim([0 10]);
title('3D Linear Fit');
grid on;
hold off;