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 个)
Walter Roberson
2022-5-25
0 个投票
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 个评论
Walter Roberson
2022-5-25
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.
William Blanch
2022-5-25
Walter Roberson
2022-5-25
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.
Walter Roberson
2022-5-25
编辑:Walter Roberson
2022-5-26
If what you are dealing with is an outline of an area then if you have the Image Processing Toolbox then
Walter Roberson
2022-5-26
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.
William Blanch
2022-5-26
Walter Roberson
2022-5-26
https://www.mathworks.com/matlabcentral/fileexchange?q=patch2stl
类别
在 帮助中心 和 File Exchange 中查找有关 STL (STereoLithography) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!