How can i connect the '.' points of the given figure. i don't want to connect '*' with any point?

조회 수: 1 (최근 30일)
%% Code that i used to creat that figure. %% I am trying to connect the dots to all nearby dots. %% To make 9 node element like as shown below. there will be Nx*Ny elements of this type.
clc ; clear;
% Dimensions of the plate
L = 1 ; % Length of the Plate along X-axes
B = 1 ; % Breadth of the Plate along Y-axes
% Number of Elements required
Nx = 3 ; % Number of Elements along X-axes
Ny = 3 ; % Number of Elements along Y-axes
%----------------------------------------
nel = Nx*Ny ; % Total Number of Elements in the Mesh
nnel = 9 ; % Number of nodes per Element
% Number of points on the Length and Breadth
npx = 2*Nx+1 ;
npy = 2*Ny+1 ;
nnode = npx*npy ;
nx = linspace(0,L,npx) ;
ny = linspace(0,B,npy) ;
[xx yy] = meshgrid(nx,ny) ;
% To get the Nodal Connectivity Matrix
coordinates = [xx(:) yy(:)] ;
NodeNo = 1:nnode ;
nodes = zeros(nel,nnel) ;
NodeNo = reshape(NodeNo,npx,npy);
%
nodes(:,1) = reshape(NodeNo(1:2:npx-2,1:2:npy-2),nel,1);
nodes(:,2) = reshape(NodeNo(3:2:npx,1:2:npy-2),nel,1);
nodes(:,3) = reshape(NodeNo(3:2:npx,3:2:npy),nel,1);
nodes(:,4) = reshape(NodeNo(1:2:npx-2,3:2:npy),nel,1);
nodes(:,5) = reshape(NodeNo(2:2:npx-1,1:2:npy-2),nel,1);
nodes(:,6) = reshape(NodeNo(3:2:npx,2:2:npy-1),nel,1);
nodes(:,7) = reshape(NodeNo(2:2:npx-1,3:2:npy),nel,1);
nodes(:,8) = reshape(NodeNo(1:2:npx-2,2:2:npy-1),nel,1);
nodes(:,9) = reshape(NodeNo(2:2:npx-1,2:2:npy-1),nel,1);
%%
X = zeros(nnel,nel) ;
Y = zeros(nnel,nel) ;
for iel = 1:nel
Y(:,iel) = coordinates(nodes(iel,:),1) ;
X(:,iel) = coordinates(nodes(iel,:),2) ;
end
x1 = X(1,:);
x2 = X(2,:);
x3 = X(3,:);
x4 = X(4,:);
x5 = X(5,:);
x6 = X(6,:);
x7 = X(7,:);
x8 = X(8,:);
x9 = X(9,:);
y1 = Y(1,:);
y2 = Y(2,:);
y3 = Y(3,:);
y4 = Y(4,:);
y5 = Y(5,:);
y6 = Y(6,:);
y7 = Y(7,:);
y8 = Y(8,:);
y9 = Y(9,:);
%%
figure
plot(x1,y1,'b.','MarkerSize',10)
xlim([-0.2 1.2])
ylim([-0.2 1.2])
hold on
plot(x2,y2,'b.','MarkerSize',10)
plot(x3,y3,'b.','MarkerSize',10)
plot(x4,y4,'b.','MarkerSize',10)
plot(x5,y5,'b.','MarkerSize',10)
plot(x6,y6,'b.','MarkerSize',10)
plot(x7,y7,'b.','MarkerSize',10)
plot(x8,y8,'b.','MarkerSize',10)
plot(x9,y9,'b*','MarkerSize',10)
hold off
  댓글 수: 2
Guillaume
Guillaume 2020년 1월 7일
In order to help we need the code that you used to create that figure (at least the line that plots the .)
Cam Salzberger
Cam Salzberger 2020년 1월 7일
Also, are you trying to connect the dots to just one other dot, to all other dots, or all "nearby" dots (like "connect the dots")?

댓글을 달려면 로그인하십시오.

채택된 답변

Asvin Kumar
Asvin Kumar 2020년 1월 16일
Try using the following code to plot:
%% Plot
lw = 2; % LineWidth
ms = 15; % MarkerSize
figure
xlim([-0.2 1.2])
ylim([-0.2 1.2])
hold on
for i = 1:Nx
plot([x1(i) x4(end-Nx+i)],[y1(i) y4(end-Nx+i)],'k-','LineWidth',lw);
end
plot([x2(Nx) x3(end)],[y2(Nx) y3(end)],'k-','LineWidth',lw);
for i = 1:Ny
plot([x1(Nx*(i-1)+1) x2(i*Nx)],[y1(Nx*(i-1)+1) y2(i*Nx)],'k-','LineWidth',lw);
end
plot([x4(Nx*(Ny-1)+1) x3(end)],[y4(Nx*(Ny-1)+1) y3(end)],'k-','LineWidth',lw);
plot(x1,y1,'b.','MarkerSize',ms)
plot(x2,y2,'b.','MarkerSize',ms)
plot(x3,y3,'b.','MarkerSize',ms)
plot(x4,y4,'b.','MarkerSize',ms)
plot(x5,y5,'b.','MarkerSize',ms)
plot(x6,y6,'b.','MarkerSize',ms)
plot(x7,y7,'b.','MarkerSize',ms)
plot(x8,y8,'b.','MarkerSize',ms)
plot(x9,y9,'b*','MarkerSize',ms)
hold off
The expected output for Nx=3 and Ny=3 is:
points.png
If you want to display a grid, it will dpend on the XTick and YTick values. Have a look at those properties at: https://www.mathworks.com/help/matlab/ref/matlab.graphics.axis.axes-properties.html#budumk7-XTick

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by