Reading particular values from a *.txt file and saving

1 view (last 30 days)
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

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 14 Jul 2014
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 Comment
Cyros
Cyros on 14 Jul 2014
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!