Reading particular values from a *.txt file and saving

조회 수: 1 (최근 30일)
Cyros
Cyros 2014년 7월 14일
댓글: Cyros 2014년 7월 14일
hi folks,
the file i've got has this format:
DATA
PIPE MEDIUM | MASS-FLOW MOLE-FLOW VOL-FLOW | PRESSURE
NO TYPE | [kg/s] [kmol/s] [m3/s] | [bar]
1 GASMIX | 0.00156 0.00005 0.00085 | 1.0000
| 0.00085 | 1.0000
2 GASMIX | 0.00156 0.00005 0.00415 | 1.0000
| 0.00415 | 1.0000
3 GASMIX | 0.00178 0.00007 0.00927 | 1.0000
VOLTAGE/CELL = 0.8000 [V]
CURRENT DENSITY = 3504.80 [A/m2]
DC-POWER = 1.6748 [kW]
AC-POWER = 1.5074 [kW]
i need to read the values of massflow of pipe nr.1 and of the ac-power. after that i need to save the values in a table after each run.
any ideas? thanks cyros

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 7월 14일
fid = fopen('file.txt');
str={};
while ~feof(fid)
str{end+1,1}=regexp(fgetl(fid),'(?<= \|).+(?=\|)','match')
end
fclose(fid);
str(cellfun(@isempty,str))=[]
str=str(3:end)
str=str(1:2:end)
a=cell2mat(cellfun(@(x) str2num(x{1}),str,'un',0))
out=a(:,1)
  댓글 수: 1
Cyros
Cyros 2014년 7월 14일
thanks, tha's a good start i guess. it gives me the value of pipe nr. 3, i need pipe nr. 1 and dc power.
i will have to work it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by