Hi! I have 29 csv file and I want to import them in Matlab. To read a single csv file, I have created this code:
Data = fileread('raffacama.csv');
Data = strrep(Data, ',', '.');
FID = fopen('raffacama2.csv', 'w');
fwrite(FID, Data, 'char');
fclose(FID);
% Import data
data=importfile('raffacama2.csv');
but I want to import simultaneously all 29 csv, so I have tried to modify the code but I have a problem
files=dir('*.csv');
for i=1:29
Users(i).Data = fileread(files(i).name);
end
All Users.Data have the values of last files.name: I don't understand why! Can you help me? Thanks

댓글 수: 5

per isakson
per isakson 2017년 2월 8일
편집: per isakson 2017년 2월 9일
This works as expected here
function Users = cssm()
files = dir('*.csv');
for jj = 1 : length( files )
Users(jj).Data = fileread(files(jj).name);
end
end
elisa ewin
elisa ewin 2017년 2월 8일
I try it but gives the same problem of my code
Stephen23
Stephen23 2017년 2월 8일
편집: Stephen23 2017년 2월 8일
@elisa ewin: you need to be specific what the problem is. Does the import work but give incorrect values, does it show warnings, do you get an error message, does your computer go into an infinite loop, or does your laptop explode? We have no idea what problem means, unless you tell us. When you tell us, then we can help you to fix that problem.
If you get any warning or error message please tell us the complete message.
elisa ewin
elisa ewin 2017년 2월 8일
this is my problem: all Users.Data have the values of last files.name and it's not right. I think the problem is clear!
per isakson
per isakson 2017년 2월 9일
The only explanation to your problem that I can think of is: All csv-file in question are identical

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

질문:

2017년 2월 8일

댓글:

2017년 2월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by