Extracting Data from a Cell as xyz information
    3 views (last 30 days)
  
       Show older comments
    
I have a script generated which extracts xyz data from a cell and plots it. This data WAS being extracted from a variable named "cross-sections" but now i need to extract data from a different variable called "polygons" which has a slightly different set up.  I can't figure out how to do this little change. Script and data are attached.
vv = polygons;
cla
hold on
for k = 1:1    %length(polygons)
    x = [vv{k}(:,1);]; %vv{k}(1,1)];
    y = [vv{k}(:,2);]; %vv{k}(1,2)];
    z = [vv{k}(:,3);]; %vv{k}(1,3)];
    plot3(x,y,z,'.-b');
    L1 = [x' ; y' ;z']; 
    N = length(x);
    % use 3 points to calculate normal vector of crossection plane
    i1 = 1;                 % first index            
    i2 = round(N/3);        % second index
    i3 = round(2*N/3);      % third index
    v1 = [x(i1)-x(i2) y(i1)-y(i2) z(i1)-z(i2)];
    v2 = [x(i1)-x(i3) y(i1)-y(i3) z(i1)-z(i3)];
    v = cross(v1,v2);       % normal vector of a plane
    a = v(1); b = v(2); c = v(3);
    % use normal vector to find approximate centroid
	x0 = (max(x)+min(x))/2;     % approximate centroid X
    y0 = (max(y)+min(y))/2;     % approximate centroid Y
    % choose first point for (px, py, pz)
    z0 = (a*(x(1)-x0) + b*(y(1)-y0))/c + z(1);
    %circle
    R = 10;
    ac  = sqrt(a*a+c*c);
    abc = sqrt(a*a+b*b+c*c);
    t1 = linspace(0,2*pi,62);
    ct = cos(t1);
    st = sin(t1);
    x1 = x0 + R/ac*(c*ct-a*b*st/abc);
    y1 = y0 + R*ac/abc*st;
    z1 = z0 - R/ac*(a*ct+b*c*st/abc); 
    %draw lines
    P = zeros([],2);
    for i = 1:length(x1)
        plot3([x0 x1(i)],[y0 y1(i)],[z0 z1(i)],'.-r')
        L2= [x0 x1(i) ; y0 y1(i) ; z0 z1(i)]; 
        %intersection points
        P(i,:) = InterX(L1,L2)';
    end
end
% Get Z for intersection points 
F = scatteredInterpolant(x,y,z) ; 
P(:,3) = F(P(:,1),P(:,2)) ; 
plot3(P(:,1),P(:,2),P(:,3),'*m')
axis equal
hold off
Thank you!!
0 Comments
Answers (1)
  Mahesh Taparia
    
 on 5 Aug 2019
        Hi, 
You can load your data using ‘load’ command. 
Your file consists of data in the form of cells (1XM) and those cells are further consists of subcells (1XN). 
You can read the Mth cell and Nth sub-cell using below code 
load polygon.mat
polygon{1,M}{1,N}
0 Comments
See Also
Categories
				Find more on Text Files 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!
