试图解析一个相当复杂的文本文件 [英] Trying to parse a fairly complex text file

查看:88
本文介绍了试图解析一个相当复杂的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个文本文件,每个文件都是模拟的结果.该文件的内容如下:

I have multiple text file, each is a result of a simulation. The content of the file is as follow:

Parameter_1 = value
Parameter_2 = value
.....

Test 1
Min: value
Max: value
Average: value

Test 2
Min: value
Max: value
Average: value

每个文件都包含具有不同值的相同类型的参数,当然测试值也不同.

Each file contains the same type of parameters with different values, and of course the tests values are different as well.

我需要能够将此数据导入到Matlab.我想在Matlab中做的是能够创建参数(x轴)和测试结果的图表.例如,更改Parameter_1Test 1 Min值的图表意味着选择仅Parameter_1不同的n个文件并比较测试1分钟"结果.

I need to be able to import this data to Matlab. What I want to do in Matlab is to be able to create charts of parameters (x-axis) and test results. For example, a chart of Test 1 Min values when Parameter_1 changes means selecting n files where only Parameter_1 differs and compare the Test 1 Min results.

这是我的问题:如何组织文本文件中的数据以使其易于导入到Matlab?我是Matlab的新手,所以我不知道什么是最好的方法.

Here's my question: how should I organize that data in my text file to make it easy to import to Matlab? I'm new to Matlab and so I'm don't know what's the best way.

任何可以帮助我入门的想法都很棒.谢谢!

Any ideas that can help me get started would be great. Thanks!

推荐答案

组织数据的最佳方式"是一个非常有争议的问题.如果问10个人,您会得到11个不同的答案.通常,它取决于数据以及可用于导入和导出数据的功能.

"Best way to organize data" is a very contentious question. If you ask 10 people you will get 11 different answers. It often depends on the data and the functionality you have available to you for importing and exporting the data.

话虽如此,Matlab在导入纯数字数据方面表现出色(哈,没有双关语).如果您可以将文件组织成仅由数字组成,则快速的加载","dlmread"或"csvread"命令将导入它们.包含文本数据会使事情复杂得多.

That being said, Matlab excels (ha, no pun intended) at importing purely numerical data. If you can organize your file to be composed of only numbers, then a quick 'load', 'dlmread', or 'csvread' command will import them. Including textual data makes things a fair bit more complex.

例如,如果文件非常一致,则可以这样组织文件:

For example, if you files are very consistent and you could organize the files like this:

Param1Value,Param2Value,Param3Value
1,Test1min,test1max,test1average
2,Test2min,test2max,test2average

示例中的所有文本都是简单的数值(整数或浮点数),因此很容易将其导入Matlab.您会知道第一行包含您的参数值

where all the text in the example are simply numerical values (integers or floats), it would be very easy to import into Matlab. You would know the first row contains your parameter values

data = csvread('input.csv');
params = data(1,:);

您可以快速提取测试编号,最小值,最大值和平均值.

And you could pull out quickly the test numbers, min, max, and average values.

tests = data(2:end,1);
mins = data(2:end,2);
maxs = data(2:end,3);
avgs = data(2:end,4);

但这全部取决于您在输出端的灵活性.

But this all hinges on how flexible you are on the output side.

这篇关于试图解析一个相当复杂的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆