Find the value at exact location in a text file

2 views (last 30 days)
Hello,
I have a huge text file which has coordinates and the pressure values for each location. I need to find the pressure values for exact locations. Is anyone know how to do it?
Any and all help would be greatly appreiciated. Thank you!
  2 Comments
Mathieu NOE
Mathieu NOE on 29 Mar 2021
hi
maybe you should share your data file and explain which data you're looking for
Yasemin Eldayih Kanber
Yasemin Eldayih Kanber on 30 Mar 2021
Edited: per isakson on 30 Mar 2021
Hi,
Below is the part of the file that I have. It has 2,800,000 lines and for example I would like to find bold data(look the end.) For a specific coordinate I need to find P value.
Thank you!
x y z p
-9.9500000E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-9.8500001E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-9.7500002E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-9.6500003E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-9.5499998E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-9.4499999E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-9.3500000E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-9.2500001E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-9.1500002E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-9.0499997E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-8.9499998E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-8.8499999E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-8.7500000E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-8.6500001E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-8.5500002E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-8.4500003E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-8.3499998E-01 4.9999999E-03 9.4999999E-02 1.2254493E+05
-8.2499999E-01 4.9999999E-03 9.4999999E-02 1.2254494E+05
-8.1500000E-01 4.9999999E-03 9.4999999E-02 1.2254494E+05
-8.0500001E-01 4.9999999E-03 9.4999999E-02 1.2254494E+05
-7.9500002E-01 4.9999999E-03 9.4999999E-02 1.2254494E+05
-7.8499997E-01 4.9999999E-03 9.4999999E-02 1.2254494E+05
-7.7499998E-01 4.9999999E-03 9.4999999E-02 1.2254494E+05
-7.6499999E-01 4.9999999E-03 9.4999999E-02 1.2254494E+05
-7.5500000E-01 4.9999999E-03 9.4999999E-02 1.2254494E+05
-7.4500000E-01 4.9999999E-03 9.4999999E-02 1.2254494E+05
-7.3500001E-01 4.9999999E-03 9.4999999E-02 1.2254494E+05
-7.2500002E-01 4.9999999E-03 9.4999999E-02 1.2254494E+05
-7.1500003E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-7.0499998E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-6.9499999E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-6.8500000E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-6.7500001E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-6.6500002E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-6.5499997E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-6.4499998E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-6.3499999E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-6.2500000E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-6.1500001E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-6.0500002E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-5.9500003E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-5.8499998E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-5.7499999E-01 4.9999999E-03 9.4999999E-02 1.2254495E+05
-5.6500000E-01 4.9999999E-03 9.4999999E-02 1.2254496E+05
-5.5500001E-01 4.9999999E-03 9.4999999E-02 1.2254496E+05
-5.4500002E-01 4.9999999E-03 9.4999999E-02 1.2254496E+05
-5.3499997E-01 4.9999999E-03 9.4999999E-02 1.2254496E+05
-5.2499998E-01 4.9999999E-03 9.4999999E-02 1.2254496E+05
-5.1499999E-01 4.9999999E-03 9.4999999E-02 1.2254496E+05
-5.0500000E-01 4.9999999E-03 9.4999999E-02 1.2254497E+05
-4.9500000E-01 4.9999999E-03 9.4999999E-02 1.2254497E+05
-4.8500001E-01 4.9999999E-03 9.4999999E-02 1.2254497E+05
-4.7499999E-01 4.9999999E-03 9.4999999E-02 1.2254497E+05
-4.6500000E-01 4.9999999E-03 9.4999999E-02 1.2254497E+05
-4.5499998E-01 4.9999999E-03 9.4999999E-02 1.2254497E+05
-4.4499999E-01 4.9999999E-03 9.4999999E-02 1.2254497E+05
-4.3500000E-01 4.9999999E-03 9.4999999E-02 1.2254498E+05
-4.2500001E-01 4.9999999E-03 9.4999999E-02 1.2254498E+05
-4.1499999E-01 4.9999999E-03 9.4999999E-02 1.2254498E+05
-4.0500000E-01 4.9999999E-03 9.4999999E-02 1.2254498E+05
-3.9499998E-01 4.9999999E-03 9.4999999E-02 1.2254498E+05
-3.8499999E-01 4.9999999E-03 9.4999999E-02 1.2254498E+05
-3.7500000E-01 4.9999999E-03 9.4999999E-02 1.2254498E+05
-3.6500001E-01 4.9999999E-03 9.4999999E-02 1.2254498E+05
-3.5500002E-01 4.9999999E-03 9.4999999E-02 1.2254498E+05
-3.4500000E-01 4.9999999E-03 9.4999999E-02 1.2254498E+05
-3.3500001E-01 4.9999999E-03 9.4999999E-02 1.2254498E+05
-3.2499999E-01 4.9999999E-03 9.4999999E-02 1.2254498E+05
-3.1500000E-01 4.9999999E-03 9.4999999E-02 1.2254498E+05
-3.0500001E-01 4.9999999E-03 9.4999999E-02 1.2254498E+05
-2.9500002E-01 4.9999999E-03 9.4999999E-02 1.2254499E+05
-2.8500000E-01 4.9999999E-03 9.4999999E-02 1.2254499E+05
-2.7500001E-01 4.9999999E-03 9.4999999E-02 1.2254499E+05
-2.6499999E-01 4.9999999E-03 9.4999999E-02 1.2254499E+05
-2.5500000E-01 4.9999999E-03 9.4999999E-02 1.2254499E+05
-2.4500000E-01 4.9999999E-03 9.4999999E-02 1.2254499E+05
-2.3500000E-01 4.9999999E-03 9.4999999E-02 1.2254499E+05
-2.2499999E-01 4.9999999E-03 9.4999999E-02 1.2254499E+05
-2.1500000E-01 4.9999999E-03 9.4999999E-02 1.2254499E+05
-2.0500000E-01 4.9999999E-03 9.4999999E-02 1.2254500E+05

Sign in to comment.

Answers (3)

Mathieu NOE
Mathieu NOE on 30 Mar 2021
hello
hope this helps
I used the attached function to load the data (FYI)
% demo
clc
clearvars;
% load data
[outdata,head] = readclm('data_ya.txt',4,1);
%
x_target = -3.1500000E-01;
y_target = 4.9999999E-03;
z_target = 9.4999999E-02;
tol = eps;
ind_x= find(abs(outdata(:,1) - x_target)< tol);
ind_y= find(abs(outdata(:,2) - y_target)< tol);
ind_z= find(abs(outdata(:,3) - z_target)< tol);
% find common single unique value accross ind_x / ind_y / ind_z
indxy_intersect = intersect(ind_x,ind_y);
indxz_intersect = intersect(ind_x,ind_z);
indxyz_intersect = intersect(indxy_intersect,indxz_intersect);
result_P = outdata(indxyz_intersect,4);

per isakson
per isakson on 30 Mar 2021
Edited: per isakson on 31 Mar 2021
An alternative construct based on ismembertol(). I believe it's faster.
%%
fid = fopen( 'cssm.txt', 'rt' ); % cssm.txt contains the data provided in the question
cac = textscan( fid, '%f%f%f%f', 'Headerlines',1, 'CollectOutput',true );
[~] = fclose( fid );
num = cac{1};
%%
ism = ismembertol( num(:,1:3) ...
, [-3.1500000E-01,4.9999999E-03,9.4999999E-02] ...
, 1 ...
, 'DataScale' , [1e-8,1e-10,1e-9] ...
, 'ByRows' , true );
format long
pressure = num( ism, 4 )
outputs
pressure =
1.225449800000000e+05
>>
Caveat: I don't understand this example from the documentation
Example: [LIA,LocB] = ismembertol(A,B,'ByRows',true,'DataScale',[eps(1) eps(10) eps(100)])
The values of 'DataScale' together with the default value of tol, 1e-12, doesn't make sense to me. That's why I explicitely set tol = 1.
In response to comment
"I have 69 points" ismembertol() handles multiple "points" nicely. Replace the second section of my script by (I just copy&pasted the two rows following your bold row.)
%%
ism = ismembertol( num(:,1:3) ...
, [ -3.1500000E-01,4.9999999E-03,9.4999999E-02
-3.0500001E-01,4.9999999E-03,9.4999999E-02
-2.9500002E-01,4.9999999E-03,9.4999999E-02 ] ...
, 1 ...
, 'DataScale' , [1e-8,1e-10,1e-9] ...
, 'ByRows' , true );
format long
locations = find( ism )
pressure = num( ism, 4 )
and you get
locations =
69
70
71
pressure =
1.0e+05 *
1.225449800000000
1.225449800000000
1.225449900000000
>>
Are all 2,800,000 locations unique?

Yasemin Eldayih Kanber
Yasemin Eldayih Kanber on 31 Mar 2021
Thank you for all answers. What if I have 69 points, not only one?
  2 Comments
Yasemin Eldayih Kanber
Yasemin Eldayih Kanber on 3 Aug 2021
Hello, I am getting this error.
pressure =
0×1 empty double column vector
Do you know how to solve it?
Thanks

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!