Reading particular values from a *.txt file and saving

1 次查看(过去 30 天)
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