Getting - Matrix dimensions must agree, using surf
Show older comments
>> 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)
Answers (1)
Walter Roberson
on 25 May 2022
0 votes
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 Comments
Walter Roberson
on 25 May 2022
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
on 25 May 2022
Walter Roberson
on 25 May 2022
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
on 25 May 2022
Edited: Walter Roberson
on 26 May 2022
If what you are dealing with is an outline of an area then if you have the Image Processing Toolbox then
Walter Roberson
on 26 May 2022
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
on 26 May 2022
Walter Roberson
on 26 May 2022
https://www.mathworks.com/matlabcentral/fileexchange?q=patch2stl
Categories
Find more on STL (STereoLithography) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!