在Matlab中读取文本文件会导致字符内的空格未知 [英] Reading text file in Matlab results in unknown spaces within characters
本文介绍了在Matlab中读取文本文件会导致字符内的空格未知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Matlab中读取text/csv文件.该文件如下所示:
I am trying to read a text/csv file in Matlab.The file looks like:
VolumeDisplacement,9783.47
CenterOfBuoyancy,-0.732585,3.16072e-14,-3.09939
WettedSurfaceArea,2709.66
WaterlineLength,102.156
MaximumWaterlineBeam,20.76
WaterPlaneArea,1774.4
CenterOfFloatation,-6.32016,1.00108e-11,0
使用Rhinoceros
中的vbscript
生成文件.我正在使用帮助文件中提供的标准方法,但是遇到了一个奇怪的问题.
The file is generated using vbscript
in Rhinoceros
. I am using the standard method given in the help file, but encountering a weird problem.
filename = 'RhinoResult.txt';
fid = fopen(filename);
line = fgetl(fid);
tline = textscan(line,'%s%d','Delimiter',',');
VolumeDisplacement=tline{2};
但是,我的结果与预期不符. tline
存储字符串,每个字符之间有一个空格.另外,开头有两个未知字符(ÿþ)
.
But, my results are not as expected. The tline
is storing the strings with a space between each character. Also, there are two unknown characters (ÿþ)
at the beginning.
tline{1} = 'ÿþV o l u m e D i s p l a c e m e n t '
用于创建文本文件的VBScript如下所示:
The VBScript used to create the textfile looks like this:
Sub writeResult(arrResults, filePath, fileName)
Dim objFSO,objFile
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(filePath & fileName, _
ForWriting, True)
objFile.Write "VolumeDisplacement," & arrResults(0)
objFile.Writeline
objFile.Write "CenterOfBuoyancy," & arrResults(1)
objFile.Writeline
objFile.Write "WettedSurfaceArea," & arrResults(2)
objFile.Writeline
objFile.Write "WaterlineLength," & arrResults(3)
objFile.Writeline
objFile.Write "MaximumWaterlineBeam," & arrResults(4)
objFile.Writeline
objFile.Write "WaterPlaneArea," & arrResults(5)
objFile.Writeline
objFile.Write "CenterOfFloatation," & arrResults(6)
objFile.Writeline
objFile.Close
End Sub
有人可以帮我吗?
谢谢, 阿米塔瓦(Amitava)
Thanks, Amitava
推荐答案
查看全文