How To Plot Data From A Cell Array Containing (x,y) Coordinates?
87 次查看(过去 30 天)
显示 更早的评论
Hi there,
I'm starting to build a vlm (Vortix Lattice Method) and in order to do so i have to divide a given area to several trapezoids.I'm using a cell array to store my data points (after the division) but I'm facing a problem plotting those points.
tl;dr - I have a 3x5 cell array and each cell is a 1x2 double matrix containing (x,y) coordinates. I Want to plot all of the points on the same graph.
Bonus Help!,
My next Stage is to draw lines connecting each point to the surrounding points in order to achieve sort of a net consists of my calculated points. Is there an easy way to do so?
Nx = 5;
Ny = 3;
Y_frame = [0 -1.5 -3 -2 0];
X_frame = [0 5 5 0 0];
line(X_frame,Y_frame)
xlim([min(X_frame-1) max(X_frame+1)]);
ylim([min(Y_frame-1) max(Y_frame+1)]);
hold on
Y_frame = Y_frame(1:4);
X_frame = X_frame(1:4);
x_dist = linspace(min(X_frame),max(X_frame),Nx);
P_upper = linediv([X_frame(1),Y_frame(1)],[X_frame(2),Y_frame(2)],Nx);
P_lower = linediv([X_frame(3),Y_frame(3)],[X_frame(4),Y_frame(4)],Nx);
plot(P_upper(1,:),P_upper(2,:),'or')
plot(P_lower(1,:),P_lower(2,:),'or')
A = cell(Ny,Nx);
for i=1:Nx
A(1,i) = {P_upper(:,i)'};
A(Ny,i) = {P_lower(:,i)'};
P_i = linediv(cell2mat(A(1,i)),cell2mat(A(end,i)),Ny);
for j=2:Ny-1
A(j,i) = {P_i(:,j)'};
end
end
Here's my code, A is the cell array i wish to plot.
Thanks in advance
回答(1 个)
Wick
2018-5-5
Niv, I assume you're putting things into a cell array on purpose. That's an unnecessary step since each element is the same shape (1,2) and they're all numbers. You could just as easily have populated a matrix like the XY matrix that results below.
Add these few lines after your code and it will plots the values in A. Given the bonus question above, I don't think A is doing what you think it's doing but perhaps I'm wrong. At least you'll be able to troubleshoot by seeing the values of A now.
XY = cell2mat(A);
X = XY(:,1:2:end);
Y = XY(:,2:2:end);
plot(X,Y,'.','MarkerSize',20);
hold off
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!