MATLAB: How to draw a surface covered by 3D line plots

how to draw a surface covered by 3d line plots

x1=[p]
y1=[vw]
Z1=[v]
for r=1:23
for n=1:23
if r==n
z1(r,n)=Z1(r,n);
else
z1(r,n)=NaN;
end
end
end
z1;
surf(log(x1),y1,z1)
I have x,y,z coordinates for 3D line plots. What I need to draw 3d the plane covered by that 3D lines. If I use the above format it does not do anything at all.
Then I removed the 'NaN' values from the Z matrices using below code.
%B = num2str(z1)'; % Convert numbers into strings.
I = strfind(B(:)','NaN'); % Find NaNs
B([I I+1 I+2]) = ' '; % Replace NaN with spaces
z1 = B'; % Display result
After that, it is saying,
23×313 char array
Z must be a matrix, not a scalar or vector.
Error in surf(log(x1),y1,z1)

Best Answer

surf() cannot draws arrays of characters. You would need to convert the characters to numbers first. That is going to be tricky for you because MATLAB numeric arrays cannot have "holes" in them.
The loop
for r=1:23
for n=1:23
if r==n
z1(r,n)=Z1(r,n);
else
z1(r,n)=NaN;
end
end
end
is equivalent to
z1 = nan(23,23));
z1(1:24:end) = diag(Z1(1:23,1:23));
which copies just the diagonal and sets all of the other elements to NaN.
This is a problem for surf(), because surf() determines the color of each face by calculating the average of the four surrounding vertices. Since only the diagonal is not nan, you can be certain that at least two of the four surrounding vertices of any face will be nan, so you can be certain that the value determined for each location will be nan, so the surf() is going to come up empty.
The arrays you show do not contain data for line plots: they contain one x, y, z coordinate per point, and the points are not ordered. Perhaps you want each point to be represented as a vector originating at (0, 0, 0) and terminating at the x, y, z coordinates?