Select only some coordinates from a .txt file

1 次查看(过去 30 天)
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')

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by