My line plot doens't work according to plot([x1 x2], [y1,y2])
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Frank Oosterveld
le 4 Déc 2018
Commenté : Frank Oosterveld
le 5 Déc 2018
I've been staring at it for a while now, but i want to make horizontal, vertical and both diagonal elements in my window,
Elem is the connection matrix, providing information about what nodes to couple. Then XY_plot is are respectively the x-value of node 1, the x-value of node 2, the y-value of node 1 and the y-value of node 2.
XY_plot = zeros(length(Elem),4);
for i = 1:length(Elem)
node_1 = Elem(i,1);
node_2 = Elem(i,2);
XY_1 = nodes(node_1,:);
XY_2 = nodes(node_2,:);
XY_plot(i,:) = [XY_1(1) XY_2(1) XY_1(2) XY_2(2)];
end
X_val = [XY_plot(:,1) XY_plot(:,2)];
Y_val = [XY_plot(:,3) XY_plot(:,4)];
%
clf, figure(1), subplot(1,2,1), hold on,
plot(X_val,Y_val,'k-')
plot(xpos,ypos,'o','MarkerFaceColor', 'y')
hold off
But this doesn't work, however the plot(X_val, Y_val) satisfies the plot([x1 x2] , [y1 y2]). Does anyone see why it doesn't work?
I attached the Elem and nodes files.
0 commentaires
Réponse acceptée
Cris LaPierre
le 4 Déc 2018
The best thing to do first is to map out the indices. From there, you will be able to see what groups of data need to be plotted together to created the lines you want. I would use multiple plot commands to achieve this rather than a single command.
4 commentaires
Cris LaPierre
le 4 Déc 2018
Hold on, your code works with a very minor adjustment.
MATLAB assumes series exist in columns. You are passing in a 342 x 2 for X and Y, so it is plotting two lines, each with 342 points (columns 1 and 2). If you instead give it a 2 x 342 it will plot 342 lines with 2 points each - your node connections.
Is that enough for you to figure out how to modify your plot command?
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
