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 Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by