Filter löschen
Filter löschen

Select only some coordinates from a .txt file

1 Ansicht (letzte 30 Tage)
Alberto Acri
Alberto Acri am 1 Dez. 2022
Kommentiert: David Hill am 2 Dez. 2022
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.

Akzeptierte Antwort

David Hill
David Hill am 1 Dez. 2022
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 Kommentare
Alberto Acri
Alberto Acri am 2 Dez. 2022
@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 am 2 Dez. 2022
I have no idea what the red nodes are.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Standard File Formats finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by