reading out a particular column with a header name from a large text file with multiple rows and columns. of different dimensions. Attached the .txt file.
조회 수: 1 (최근 30일)
이전 댓글 표시
I couldnot find a solution for reading out a particular column with a header name in text file with multiple row and columns of different dimensions. Attached the .txt file for reference. The intention is to read out all the numbers under the column header name N482.
I would appreciate the help!
Smruti
댓글 수: 0
채택된 답변
Mathieu NOE
2021년 9월 28일
hello
I am not sure if you ask for the data in the N482 rows (and not column) as we can see in the first 49,407 lines of your data file
or if we are talking about some columns in the very lower end of the data file where N482 also sometimes appear but seems asociated with many different variables
in case the good answer is correponding to the first scenario, here a little code that will retrieve the data :
clc
clearvars
%%% main code %%%
[ data_out ] = retrieve_data('PerformanceResults.txt');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ data_out ] = retrieve_data(Filename)
fid = fopen(Filename);
tline = fgetl(fid);
% initialization
k = 0;
p = 0;
data_line = [];
while ischar(tline)
k = k+1; % loop over line index
tmp1 = contains(tline,'N482:');
if tmp1 && ~isempty(tline)
p = p+1;
ind1 = strfind(tline,':');
ind2 = strfind(tline,'[');
data_out(p,1) = str2double(tline(ind1+1:ind2-1)); %
end
tline = fgetl(fid);
end
fclose(fid);
end
댓글 수: 4
Mathieu NOE
2021년 9월 28일
hello
ok but I still have a few questions , like
N481 , no more N482 ?
when i search for N481 in the specified rows , I can find it under different variables / units like :
EF1.Ncrel
N481
[-]
________________________
0.1000000000000000E+01
0.9162897600284080E+00
0.7497359606957799E+00
0.8814135438000129E+00
EFAN1Shaft.N
N481
[rpm]
_______________________
0.8000000000000000E+04
0.7168221667751842E+04
0.6176755811549974E+04
0.7745871554961489E+04
EF1.Ncrel
N481
[-]
_______________________
0.1000000000000000E+01
0.9162897600284080E+00
0.7497359606957799E+00
0.8814135438000129E+00
EFAN1Shaft.N
N481
[rpm]
________________________
0.8000000000000000E+04
0.7168221667751842E+04
0.6176755811549974E+04
0.7745871554961489E+04
EF1.Ncrel
N481
[-]
_______________________
0.1000000000000000E+01
0.9162897600284080E+00
0.7497359606957799E+00
0.8814135438000129E+00
EFAN1Shaft.N
N481
[rpm]
______________________
0.8000000000000000E+04
0.7168221667751842E+04
0.6176755811549974E+04
0.7745871554961489E+04
EF1.Ncrel
N481
[-]
_______________________
0.1000000000000000E+01
0.9162897600284080E+00
0.7497359606957799E+00
0.8814135438000129E+00
and so on...
how do I have to understand how we organize the retrieval of data ? we cannot simply put together what is different topic
for PWX481 same question
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!