필터 지우기
필터 지우기

How can read .csv file in matlab

조회 수: 6 (최근 30일)
mulus
mulus 2015년 9월 21일
댓글: Sajid Afaque 2020년 6월 16일
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
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
Yogesh Badhe 2015년 9월 21일
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.
  댓글 수: 1
mulus
mulus 2015년 9월 21일
Hello JPro,
I am using MATLAB 7.8.0 R2009a. I have frequent.m file , It contains a function function [frequentItemsets]= frequent(Transaction,Support) I want to read .csv file which contains transactions and store it as a cell array to count the occurrence frequency of each item.
thanks .

댓글을 달려면 로그인하십시오.


Walter Roberson
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
Walter Roberson
Walter Roberson 2015년 9월 21일
Replace YourFile.csv with the actual name of your file.
Sajid Afaque
Sajid Afaque 2020년 6월 16일
what if i have variable numer of columns and rows

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by