필터 지우기
필터 지우기

Select only some coordinates from a .txt file

조회 수: 1 (최근 30일)
Alberto Acri
Alberto Acri 2022년 12월 1일
댓글: David Hill 2022년 12월 2일
Hi!
I have the filename.txt file representing the coordinates of the nodes.
I have a nodes.txt file that represents the row I want to keep within the filename.txt file.
How can I locate the nodes I want?
For example:
the number 1 in the nodes.txt file represents the coordinate (307, 55) of the filename.txt file
the number 26 in the nodes.txt file represents the coordinate (308, 45) of the filename.txt file
and so on...
I want to bring back to the workspace only the coordinates of interest.

채택된 답변

David Hill
David Hill 2022년 12월 1일
n=readmatrix('nodes.txt');
m=readmatrix('filename.txt');
newMatrix=m(n,:)
newMatrix = 223×2
307 55 307 54 307 53 307 52 307 51 307 50 307 49 307 48 307 47 307 46
  댓글 수: 2
Alberto Acri
Alberto Acri 2022년 12월 2일
@David Hill could you help me with this code as well?
I would like to display only the red nodes.
data = readmatrix('filename_3.txt');
x = data(:,1);
y = data(:,2);
s = 1;
gap = 1;
yy = unique(sort(y));
ind = find(diff(yy)>gap);
val_low = yy(ind);
val_upper = yy(ind+1);
y_threshold = (val_low+val_upper)/2; % let's take the average of the two
% same approach to find x gap between left / right
xx = unique(sort(x));
ind = find(diff(xx)>gap);
val_low = yy(ind);
val_upper = yy(ind+1);
x_threshold = (val_low+val_upper)/2; % let's take the average of the two
%upper left curve
idx = x<x_threshold;
idy = y>y_threshold;
x_temp = x(idx & idy);
y_temp = y(idx & idy);
k_UL = boundary(x_temp,y_temp,s);
x_out1 = x_temp(k_UL);
y_out1 = y_temp(k_UL);
%upper right curve
idx = x>x_threshold;
idy = y>y_threshold;
x_temp = x(idx & idy);
y_temp = y(idx & idy);
k_UR = boundary(x_temp,y_temp,s);
x_out2 = x_temp(k_UR);
y_out2 = y_temp(k_UR);
%lower left curve
idx = x<x_threshold;
idy = y<y_threshold;
x_temp = x(idx & idy);
y_temp = y(idx & idy);
k_LL = boundary(x_temp,y_temp,s);
x_out3 = x_temp(k_LL);
y_out3 = y_temp(k_LL);
%lower right curve
idx = x>x_threshold;
idy = y<y_threshold;
x_temp = x(idx & idy);
y_temp = y(idx & idy);
k_LR = boundary(x_temp,y_temp,s);
x_out4 = x_temp(k_LR);
y_out4 = y_temp(k_LR);
plot(x,y, '.', x_out1, y_out1, '.r', x_out2, y_out2, '.r', x_out3, y_out3, '.r', x_out4, y_out4, '.r')
David Hill
David Hill 2022년 12월 2일
I have no idea what the red nodes are.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by