How to draw a surface covered by 3D line plots
    1 view (last 30 days)
  
       Show older comments
    
    Chathurika Jayasundara
 on 11 Sep 2018
  
    
    
    
    
    Answered: Walter Roberson
      
      
 on 11 Sep 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 Comments
  madhan ravi
      
      
 on 11 Sep 2018
				
      Edited: madhan ravi
      
      
 on 11 Sep 2018
  
			select the whole code and click the code button
Accepted Answer
  Walter Roberson
      
      
 on 11 Sep 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?
0 Comments
More Answers (0)
See Also
Categories
				Find more on Surface and Mesh Plots 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!

