How can read .csv file in matlab
显示 更早的评论
Hi,
I have a .csv file which contains both string and numbers , the first raw contains columns name which is string and the rest of raw's contains integer value . my file look like
Id age sex subject
12 21 1 3
I want to read it and store it as a cell array for counting the frequent itemsets . how can I do that . please help me.
Thank you.
1 个评论
Renato Agurto
2015-9-21
Hi. Can you open your csv file with a text editor and see which separator is used for the values: ' ,' or ' ;' ?
回答(2 个)
Yogesh Badhe
2015-9-21
0 个投票
If you have MATLAB R2014a or later version you have "Import data" tab on main window under Home tab. Just click on that, browse to your desired file and click import. Thats it.
Walter Roberson
2015-9-21
If you are using a new enough version of MATLAB (might require R2015b), then csvread() should work if you pass it parameters that tell it to skip the first line
Otherwise,
fid = fopen('YourFile.csv','rt');
datacell = textscan(fid, '%d%d%d%d', 'HeaderLines',1,'Delimiter',',','CollectData', 1);
fclose(fid);
now datacell{1} is your numeric matrix
3 个评论
mulus
2015-9-21
Walter Roberson
2015-9-21
Replace YourFile.csv with the actual name of your file.
Sajid Afaque
2020-6-16
what if i have variable numer of columns and rows
类别
在 帮助中心 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!