Getting - Matrix dimensions must agree, using surf

>> Paving
??? Error using ==> surface
Matrix dimensions must agree.
Error in ==> C:\MATLAB6p1\toolbox\matlab\graph3d\surf.m
On line 68 ==> hh = surface(varargin{:});
Error in ==> D:\Matlab\MATLAB6p1\work\Paving.m
On line 38 ==> surf(X,Y,Z)

回答(1 个)

When you call surf(X, Y, Z) in your very old release, the number rows in Z must match the number of rows in Y and the number of columns in Z must match the number of columns in X. However in your code, X, Y, Z are all vectors.
surf() can never be used to turn a set of scattered points into a surface.

7 个评论

That version of MATLAB is 20 years old, and I no longer recall what you would have to do in order to create a surface from scattered points for it. Something similar to using qhull() to create some kind of triangulation and creating a mesh from that.
The recommended approach has changed at least twice in the 20 years since your release.
Thank You Mr. Roberson for your help. It works for the attached code (an example).
What I am doing is using Moasure One to get 3D data for a plot of land. It outputs to me the x,y,z coordinates in an Excel file and I want to get an stl file from the surface plot and open the flie in Solidworks as a part and use it as the base of an assembly that adds the design of a house that is going to be built on the plot of land.
Billy
That example has each of x1 and so on be a column vector. When you [] five of those together you get an Nx5 array. Your X, Y, Z are then 2d arrays.
Your earlier code is using single columns for each of the x y z, and surf() cannot work with vectors.
If what you are dealing with is an outline of an area then if you have the Image Processing Toolbox then
Your original data appears to be an ordered list of points in 3 space.
It is not obvious what it means to draw a surface plot of it. I suspect, though, that what you want would be something similar to taking the X Y Z vertices and duplicating them with a slightly larger Z, and then drawing connecting lines between the original X Y Z and the X Y (Z+delta) . You could do that with patch() with the Faces and Vertices inputs
XYZ2 = [X, Y, Z; X, Y, Z+delta];
faces(1,:) = 1:length(X);
faces(2,:) = fliplr(length(X)+1:2*length(X)); %opposite side, should go backwards
then create a series of additional rows that individually define rectangles in a consistent orientation, with the unused entries in each row being set to NaN.
Thank You, but what I need is an .stl file so that I can create a part of it in Solidworks. Can you get an .stl file from a patch?
https://www.mathworks.com/matlabcentral/fileexchange?q=patch2stl

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by