To plot the surface for a table with arbitrary X,Y,ZX, Y, Z values, you need to organize the ZZ values into a grid format that corresponds to X,YX, Y pairs. The function surf
requires ZZ to be a 2D matrix, where each element corresponds to a specific X,YX, Y pair.
Here’s how you can handle this step by step:
griddata
or accumarray
to arrange ZZ values into a grid based on unique XX and YY values.surf
to create the plot.
% Define your table data X = [1; 1; 1; 2; 2; 2; 3; 3; 3]; % X-coordinates Y = [1; 2; 3; 1; 2; 3; 1; 2; 3]; % Y-coordinates Z = [0.1711; 0.0326; 0.5612; 0.8819; 0.6692; 0.1904; 0.3689; 0.4607; 0.9816]; % Z-values
Solution:
% Create a grid of unique X and Y values [Xq, Yq] = meshgrid(unique(X), unique(Y)); % Interpolate Z values into the grid using griddata Zq = griddata(X, Y, Z, Xq, Yq); % Plot the surface surf(Xq, Yq, Zq); % Add labels and title xlabel('X'); ylabel('Y'); zlabel('Z'); title('Surface Plot from Arbitrary X, Y, Z Data'); colorbar;
X
, Y
, and Z
should be column vectors, as in your example.griddata
: This function interpolates scattered data into a regular grid, making it suitable for surface plotting.surf
plots the 3D surface.colorbar
for better visualization of ZZ-values.The error occurred because surf
requires ZZ to be a matrix matching the dimensions of XX and YY. By using griddata
to interpolate or organize ZZ, you convert it into a compatible format.
With this approach, you can handle any arbitrary X,Y,ZX, Y, Z data imported as a table!
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.