English 中文(简体)
如果档案大多是文本,我如何在MATLAB使用“Textscan”的一系列数字读?
原标题:How do I read in a series of numbers using "Textscan" in MATLAB if the file is mostly text?

我有一份文本文件,有3个数字,我需要读作MATLAB。

例:

#######################
#
#
#    Text Text Text
#
#
#######################

Blah blah blah = ####
Blah blah blah = ####
Blah blah blah = ####
Blah blah blah = ####
Blah blah blah = ####
Blah blah blah = ####


I_NEED_THIS_STRING =  1234.5 6789.0 1234.5 !Comment blah blah blah

我需要把这3个数字读成一个阵列。

PLEASE HELP。

增 编

最佳回答

如果大多数档案与你的申请不相干,我建议进行预处理,使用你有利的描述语言或指挥线工具,以找到相关路线,并使用有关文本。

e. 例如,从单壳起:

grep ^I_NEED_THIS_STRING infile > outfile

a. 在校:

fid = fopen( outfile );
C = textscan(fid,  I_NEED_THIS_STRING = %f %f %f )
fclose(fid)

详情见rel=“nofollow noreferer”>textscan documentation

问题回答




相关问题
Is There Any Way Without File.ReadAllText?

As I love to develop file I/O applications and my new development platform is Windows Mobile. Is there any way to read all the file, without using File.ReadAllText? Because Windows Mobile doesn t ...

File paths in Java (Linux)

I have created a Java application that loads some configurations from a file conf.properties which is placed in src/ folder. When I run this application on Windows, it works perfectly. However when I ...

How do I create a string using a loop variable in MATLAB?

I have a loop like this: for i=1:no %some calculations fid = fopen( c:\out.txt , wt ); %write something to the file fclose(fid); end I want data to be written to different files like ...

热门标签