zl程序教程

您现在的位置是:首页 >  其他

当前栏目

matlab将txt数据分类,MATLAB读取txt文件,txt里面有字符串和数值两种类型

文件MATLAB数据 类型 字符串 读取 分类 两种
2023-06-13 09:13:41 时间

大家好,又见面了,我是你们的朋友全栈君。

MATLAB读取txt文件,txt里面有字符串和数值两种类型

mip版 关注:96 答案:4 悬赏:30

解决时间 2021-01-29 08:48

已解决

2021-01-28 15:04

MATLAB读取txt文件,txt里面有字符串和数值两种类型,将txt文件读入MATLAB里,并得到一个矩阵。txt文件里面的数据如下:

5.1,3.5,1.4,0.2,Iris-setosa

4.9,3.0,1.4,0.2,Iris-setosa

4.7,3.2,1.3,0.2,Iris-setosa

4.6,3.1,1.5,0.2,Iris-setosa

5.0,3.6,1.4,0.2,Iris-setosa

5.4,3.9,1.7,0.4,Iris-setosa

4.6,3.4,1.4,0.3,Iris-setosa

5.0,3.4,1.5,0.2,Iris-setosa

4.4,2.9,1.4,0.2,Iris-setosa

4.9,3.1,1.5,0.1,Iris-setosa

5.4,3.7,1.5,0.2,Iris-setosa

4.8,3.4,1.6,0.2,Iris-setosa

4.8,3.0,1.4,0.1,Iris-setosa

4.3,3.0,1.1,0.1,Iris-setosa

5.8,4.0,1.2,0.2,Iris-setosa

5.7,4.4,1.5,0.4,Iris-setosa

5.4,3.9,1.3,0.4,Iris-setosa

5.1,3.5,1.4,0.3,Iris-setosa

5.7,3.8,1.7,0.3,Iris-setosa

5.1,3.8,1.5,0.3,Iris-setosa

5.4,3.4,1.7,0.2,Iris-setosa

5.1,3.7,1.5,0.4,Iris-setosa

4.6,3.6,1.0,0.2,Iris-setosa

5.1,3.3,1.7,0.5,Iris-setosa

4.8,3.4,1.9,0.2,Iris-setosa

5.0,3.0,1.6,0.2,Iris-setosa

5.0,3.4,1.6,0.4,Iris-setosa

5.2,3.5,1.5,0.2,Iris-setosa

5.2,3.4,1.4,0.2,Iris-setosa

4.7,3.2,1.6,0.2,Iris-setosa

4.8,3.1,1.6,0.2,Iris-setosa

5.4,3.4,1.5,0.4,Iris-setosa

5.2,4.1,1.5,0.1,Iris-setosa

5.5,4.2,1.4,0.2,Iris-setosa

4.9,3.1,1.5,0.1,Iris-setosa

5.0,3.2,1.2,0.2,Iris-setosa

5.5,3.5,1.3,0.2,Iris-setosa

4.9,3.1,1.5,0.1,Iris-setosa

4.4,3.0,1.3,0.2,Iris-setosa

5.1,3.4,1.5,0.2,Iris-setosa

5.0,3.5,1.3,0.3,Iris-setosa

4.5,2.3,1.3,0.3,Iris-setosa

最佳答案

2021-01-28 16:37

function fun()

temdat=load(‘D:\test.txt’);

if temdat== -1

(‘Error opening the file’);

end

A=[temdat(:,1),temdat(:,2),temdat(:,3))];

全部回答

1楼

2021-01-28 18:39

如果没有答案,那就用其他的方法吧。

可以先用ultraedit的 列模式 把后面的删了,然后再用matlab读入

2楼

2021-01-28 17:44

使用textscan函数。

3楼

2021-01-28 17:32

你好!

用csvread或者dlmread都能完成你的要求,textscan也能,但是需要指定格式

如果对你有帮助,望采纳。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/197577.html原文链接:https://javaforall.cn