How To Plot Data From A Cell Array Containing (x,y) Coordinates?
87 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
2 Commenti
Risposte (1)
Wick
il 5 Mag 2018
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 Commenti
Vedere anche
Categorie
Scopri di più su Line Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!