Filter löschen
Filter löschen

Reading particular values from a *.txt file and saving

1 Ansicht (letzte 30 Tage)
Cyros
Cyros am 14 Jul. 2014
Kommentiert: Cyros am 14 Jul. 2014
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

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 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 Kommentar
Cyros
Cyros am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by