Find the value at exact location in a text file
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Yasemin Eldayih Kanber
el 29 de Mzo. de 2021
Comentada: Yasemin Eldayih Kanber
el 3 de Ag. de 2021
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 comentarios
Mathieu NOE
el 29 de Mzo. de 2021
hi
maybe you should share your data file and explain which data you're looking for
Respuestas (3)
Mathieu NOE
el 30 de Mzo. de 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);
0 comentarios
per isakson
el 30 de Mzo. de 2021
Editada: per isakson
el 31 de Mzo. de 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
>>
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?
0 comentarios
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!