Extracting Nodes in MATLAB

8 views (last 30 days)
Sushant
Sushant on 24 Nov 2022
I have generated a RVE. After meshing, i want to extract the nodes of the two opposite edges in MATLAB. I have use the code below, but it is giving blank.
clear;
fileID = fopen('new.txt');
formatSpec = '%s';
N = 8;
% reads file data, using the formatSpec N times
% c_h: cell header
c_h = textscan(fileID,formatSpec,N,'delimiter','|');
% Read coordinates for nodes on the two opposite surfaces
% Save them in a cell array whose first and fourth columns are node #
% rest columns are x,y,z coordinates
% c_cord
c_cord = textscan(fileID,'%d %f %f %f %d %f %f %f');
fclose(fileID);
%%
% Turn cell array which stored coordinates info. for points on left and
% right side of RVE into a sorted matrix
% Initialize matrix
cordMatrix=[];
for i=1:N
c1_cell=c_cord(1,i);
c1_elem=c1_cell{1,1};
cordMatrix(:,i)=c1_elem;
end
% Sort the matrix by the third column-Y coordinates
% sortedMatrixByLy-sorted matrix by left y coordinates
sortedMatrixByLy=sortrows(cordMatrix, 3);
% sortedMatrixByRy-sorted matrix by right y coordinates
sortedMatrixByRy=sortrows(cordMatrix, 3);
%%
% pairwise distance between left and right side sets of points
% # of points on Left side and right side do NOT have to the the same
Left=sortedMatrixByLy(:,1:4);
Right=sortedMatrixByRy(:,5:8);
% Fetch the x,y,z coordinates of left side points
LC=Left(:,2:4);
% Fetch the x,y,z coordinates of right side points
RC=Right(:,2:4);
% Compute all the distances between points on left and right side
% i.e. left has M points, right has N points, size of D matrix is M*N
D = pdist2(LC,RC);
%%
% Find the minimum distance value in each row of D and
% return the corresponding indices
DD=D;
[Sml,ind] = min(DD,[],2);
for j=1:size(DD,1)
[Sml(j),ind(j)] = min(DD(j,:),[],2);
% Replace the value in the same column of ind(j) by a very large number
% eg.999999 in here to avoid duplicat indice (i.e. the same point on one
% side used more than once)
DD(:,ind(j))=999999;
end
% Based on the returned indices find the paired points on left and right
% sides which has minimum distances
% The paired nodes then can be incorporated into FEA package Abaqus input file to
% define Periodic Boundary Conditions by using "Equations" in Abaqus
% pn:parid nodes
pn=[Left(:,1) Right(ind,1)]

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!