How to draw a surface covered by 3D line plots

2 visualizaciones (últimos 30 días)
Chathurika Jayasundara
Chathurika Jayasundara el 11 de Sept. de 2018
Respondida: Walter Roberson el 11 de Sept. de 2018
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)
  2 comentarios
madhan ravi
madhan ravi el 11 de Sept. de 2018
Editada: madhan ravi el 11 de Sept. de 2018
select the whole code and click the code button
Chathurika Jayasundara
Chathurika Jayasundara el 11 de Sept. de 2018
Sorry, I didn't get you. Are you saying the run button?

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 11 de Sept. de 2018
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?

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by