saving a .csv file with text values as a .mat file

2 次查看(过去 30 天)
I tried using csvread, but it only accepts csv files with numeric values. I want to convert a csv file e.g. fisheriris.csv to .mat file, how can i do that?
Also, how to change the class labels with numbers or letters like a,b,c.. ?

采纳的回答

Walter Roberson
Walter Roberson 2019-2-19
T = readtable('fisheriris.csv');
Tlabcat = categorical(T{:,5});
Tcats = categories(Tlabcat);
Tlabnum = double(Tlabcat);
Tnum = [T{:,1:4}, Tlabnum];
Now Tcats is a cell array of character vectors indicating the category names, and Tnum is a double array of the data, with the last column being a class number converted from the text category labels.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by