My line plot doens't work according to plot([x1 x2], [y1,y2])
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Frank Oosterveld
el 4 de Dic. de 2018
Comentada: Frank Oosterveld
el 5 de Dic. de 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 comentarios
Respuesta aceptada
Cris LaPierre
el 4 de Dic. de 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 comentarios
Cris LaPierre
el 4 de Dic. de 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?
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
