Extracting Data from a Cell as xyz information

3 ビュー (過去 30 日間)
Devrim Tugberk
Devrim Tugberk 2019 年 7 月 31 日
回答済み: Mahesh Taparia 2019 年 8 月 5 日
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!!

回答 (1 件)

Mahesh Taparia
Mahesh Taparia 2019 年 8 月 5 日
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}

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by