- File Existence & Path: Ensure new.txt is in the correct directory.
- Delimiter: Verify that the delimiter in your file matches '|'. If the file uses spaces or another delimiter, adjust accordingly in textscan.
- Format Specification: Ensure the format in textscan matches your file's structure. Adjust %d %f %f %f %d %f %f %f if necessary.
- Matrix Initialization: Verify that cordMatrix is initialized correctly and c_cord has data.
- Debugging: Use disp to print intermediate results for verification.
Extracting Nodes in MATLAB
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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)]
0 Kommentare
Antworten (1)
Abhinaya Kennedy
am 26 Aug. 2024
If these suggestions don't resolve the issue, consider providing a sample of your new.txt file so that the community can offer more specific advice.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!