将带有两个不同分隔符的txt文件加载到struct中

时间:2015-01-16 08:30:50

标签: matlab file struct loading

我在Matlab中加载 .txt 文件时遇到问题。主要问题是没有相等的行。我会附上档案,这样你就可以更清楚地看到我想说的话了。首先,该文件包含有关图中每个节点的信息。一行有这样的信息:

1|1|EL_1_BaDfG|4,41|5,1|6,99|8,76|9,27|13,88|14,19|15,91|19,4|21,48...

意思是:

id|type|name|connected_to, weight|connected_to, weight| and so on..

我试图使用fscanf函数,但它只将整行读作一个字符串。我怎么想用我需要的信息把它分成结构?

致以最诚挚的问候,

德扬

Here, you can see file that I'm trying to load

1 个答案:

答案 0 :(得分:0)

Stewie 答案的替代方法是使用:

fgetl   to read each line

然后使用

strread (or textscan) to split the string 

首先使用|分隔符 - 然后在包含,的子部分再次执行。