フィルターのクリア

I would to save the values for post processing from file output, can you help me?

3 ビュー (過去 30 日間)
mattvanviore
mattvanviore 2019 年 5 月 4 日
編集済み: per isakson 2019 年 5 月 23 日
I have a file .txt which i would to obtain the values for post processing. For this in Matlab i am using:
outputfile=fopen(postproces.dat,'r');
But the file have this line:
fan= 30.000 bes = 2.3700 doe = 15.490
and i would to catch 2.3700 and save it into a variabile bes in Matlab. Thanks.

採用された回答

per isakson
per isakson 2019 年 5 月 5 日
編集済み: per isakson 2019 年 5 月 7 日
Try this
>> num = cssm('h:\m\cssm\postprocessing.txt')
num =
3.15
where the file, cssm.m, contains the following code
function num = cssm( ffs )
str = fileread( ffs );
xpr = '(?<=Cref\s*=\s*)[0-9.]+';
cac = regexp( str, xpr, 'match', 'once' );
num = str2double( cac );
end
2017-05-07: There is an issue with this regular expression, '(?<=Cref\s*=\s*)[0-9.]+'. It matches the value following any word that ends with the string, Cref, e.g. xyzCref. Thus, add the beginning of word anchor, \<, so that the expression reads '(?<=\<Cref\s*=\s*)[0-9.]+'.
Version 2.0
>> num = cssm('h:\m\cssm\postprocessing.txt',{'Sref','Cref','Bref'})
num =
30 3.15 10.95
where
function num = cssm( ffs, names )
narginchk(1,2)
if nargin == 1
names = {'Cref'};
else
if isa( names, 'char' )
names = {names};
elseif not( iscellstr( names ) )
error('The second input argument, "%s", has wrong type')
end
end
str = fileread( ffs );
len = length( names );
num = nan( size( names ) );
for jj = 1 : len
xpr = ['(?<=\<', names{jj}, '\s*=\s*)[0-9.]+'];
cac = regexp( str, xpr, 'match', 'once' );
num(jj) = str2double( cac );
end
end
  2 件のコメント
mattvanviore
mattvanviore 2019 年 5 月 22 日
I'm using num = cssm( ffs ) and have a problem when the value is negative, and it appears NaN.
per isakson
per isakson 2019 年 5 月 22 日
編集済み: per isakson 2019 年 5 月 23 日
What's "value is negative" and what's "appears NaN" ?

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2019 年 5 月 4 日
You can probably use csvread(), dlmread(), readtable(), importdata(), textscan(), or fgetl(). (Just one of those functions of course!)
If none of those work, attach 'postproces.dat' so we can figure it out for you.
  4 件のコメント
mattvanviore
mattvanviore 2019 年 5 月 5 日
I want to save automatically as a variable Cref the value 3.1500 and as variable Cdind the value 0.1076431. I am using this code for the scan:
dati=fopen(['.\folder\postprocessing.txt'],'r');
for i=1:8
tline=fgets(dati);
end
per isakson
per isakson 2019 年 5 月 5 日
編集済み: per isakson 2019 年 5 月 5 日
Your file, postprocessing.txt, looks like this
---------------------------------------------------------------
Vortex Lattice Output -- Total Forces
Configuration: ALA ANALISI lambda0.2-massa 2000kg-AR 4
# Surfaces = 2
# Strips = 40
# Vortices = 240
Sref = 30.000 Cref = 3.1500 Bref = 10.950
Xref = 0.0000 Yref = 0.0000 Zref = 0.0000
CDvis = 0.00000 CDind = 0.1076431
Do the files always have 12 lines and this format?
What about the line, fan= 30.000 bes = 2.3700 doe = 15.490 , of your question?
Do you want to capture only the value of Cref ?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by