How do I choose specific data from a .txt file and then find the average, max and min values
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sam Bailey
el 7 de Feb. de 2020
Comentada: Sam Bailey
el 10 de Feb. de 2020
Hi, I'm fairly new to using matlab and I would like to know how to make a generic code so that I can extract the figures in bold in order to find the average, minimum and maximum values even when their values change. Any help with this wouldbe appreciated thanks.
iQ-Analyzer V6.2.2.1
FileName: U:\test.txt
FileDate: 04-Feb-2020 14:18:05
ChartFile: TE281
FileName dark: -
Make: - Firmware: noExif
Model: - Serial: Lens:
Aperture: 0.0 Aperture_eff: 0.0
Exp.Time: 0.000000
ISO: 0
Exp.Bias: -
FocalLength: 0.0
Measurement type: C
X [Pixel]: 1280 Y [Pixel]: 800 X [mm]: Y [mm]: PixelCount [MP]: 1.0 PixelPitch [�m]:
Illumination [Lux]: 1000
Notes:
F[%]
Pos. Avg. field Average F[%] Q1 field Q1 F[%] Q2 field Q2 F[%] Q3 field Q3 F[%] Q4 field Q4 F[%]
Center 0.00467498 11.9126 0.00467498 11.9126 0.00467498 11.9126 0.00467498 11.9126 0.00467498 11.9126
H1 0.178026 9.93692 0.176921 9.88428 0.174292 9.6432 0.179058 9.96143 0.181832 10.2588
H2 0.358703 8.7754 0.359936 8.77699 0.354776 8.6757 0.357503 8.78022 0.362599 8.86868
H3 0.538969 8.58128 0.543139 8.74501 0.535175 8.81967 0.533882 8.37896 0.543682 8.38149
H4 0.714701 9.32563 0.724523 9.71568 0.710426 9.47228 0.704348 8.96331 0.719507 9.15123
0 comentarios
Respuesta aceptada
Marcelo
el 7 de Feb. de 2020
Try this:
fid = fopen('test.txt');
is_start_point = false;
values = {};
while 1
current_line = fgetl(fid);
if ~ischar(current_line), break, end
if strcmp(strtrim(current_line),'F[%]')
is_start_point = true;
continue
end
if is_start_point
broken_line = strsplit(current_line, '\t', 'CollapseDelimiters', true);
broken_line(cellfun('isempty',broken_line)) = [];
values = [values;broken_line];
end
end
fclose(fid);
title = values(1,:);
numbers = values(2:end,2:end);
numbers = cellfun(@str2double,numbers);
max_number = max(numbers)
min_number = min(numbers)
mean_number = mean(numbers)
Maybe, depend on your Matlab version, some commands won't work. In this case, just search for another one similar in your version.
3 comentarios
Marcelo
el 10 de Feb. de 2020
Hi, Sam.
Maybe the test.txt file I'm using is not exactly equal yours. Could you attach an example file to better work on this problem?
By the way, which Matlab version are you using?
Más respuestas (1)
Marcelo
el 7 de Feb. de 2020
Sam,
Is your text file exactly like this one you pasted in your question? I mean, the eleventh element is actually in a new line or this just happened when you pasted the values here?
1 comentario
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!