在matlab中读取CSV文件 [英] Reading CSV file in matlab
本文介绍了在matlab中读取CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个csv文件,像这样的格式:
I have a csv file like this format:
2.3 , 1.3 , 1.2 , 6.8 , classone
1.2 , 2.6 , 1.8 , 0.7 , classtwo
我想将文件读入seprate矩阵;一个矩阵中的前4个数字值和另一个矩阵中的字符串值
I want to read the file into seprate matrix; the first 4 numeric values in one matrix and the string value in another matrix
我尝试了textscan函数,但它不能很好地工作
I have tried textscan function but it doesnt work well
M= textread('training.dat','%f %f %f %f %s');
Error using dataread
Number of outputs must match the number of unskipped
input fields.
推荐答案
尝试
[num, str, ~] = xlsread('training.dat');
fid = fopen('training.dat');
D = textscan( ...
fid, '%f%f%f%f%s', ...
'Delimiter', ' , ', ...
'MultipleDelimsAsOne', true ...
);
fclose(fid);
numeric_stuff = horzcat(D{1:4});
string_stuff = D{5};
这篇关于在matlab中读取CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文