Unable to read data with .clv extension
이전 댓글 표시
Hi,
I am trying to import multiple csv files into Matlab (.csv extension) but I am keep getting an empty structure.
Following online suggestions I used the following line of code:
d = dir('/Users/file_*.clv');
images = arrayfun(@(f) csvread(f.name), dircontent, 'UniformOutput', false);
image = cat(3, images{:});
For some reason seems like Matlab doesn't read the data. I got the following when I checked the size(image). I was expecting a 3D array instead.
ans =
0 0
Below the code I used with the .csv extension:
d = dir('/Users/file_*.csv');
images = arrayfun(@(f) csvread(f.name), dircontent, 'UniformOutput', false);
image = cat(3, images{:});
I got the following error:
>> mult_csv
Error using csvread (line 35)
File not found.
Error in mult_csv>@(f)csvread(f.name)
Error in mult_csv (line 8)
images = arrayfun(@(f) csvread(f.name), dircontent, 'UniformOutput', false);
Any ideas?
P.S. I attached an example of my csv files.
댓글 수: 5
Guillaume
2018년 7월 26일
Your question is confusing, the two dir you show return a completely different set of files. The first ones, files ending in .clv, the second one ending in .csv. We don't know what's in these files but, presumably, something completely different, so I don't see why matlab would read both the same way.
Speaking of which, you say that matlab reads the data but don't show us the code you actually you use to read that data. There are many functions to import data, each tailored to a specific file format.
And finally, for us to know what function to use, we'd need to see a sample file.
KALYAN ACHARJYA
2018년 7월 26일
Agreed!
"For some reason seems like Matlab doesn't read the data."
None of the code you have shown reads any file data into MATLAB. Either you have forgotten to show us the code that you actually use to import that data, or you need to read the documentation on how to import data:
Mar
2018년 7월 26일
Guillaume
2018년 7월 26일
For some reason, I missed that you commented there (There was a problem yesterday where the activity feed stopped updating for a few hours). I've now updated my answer.
답변 (1개)
KALYAN ACHARJYA
2018년 7월 26일
편집: KALYAN ACHARJYA
2018년 7월 30일
% Please save all files name in symmetrically before doing the operation
%keep in all one folder, so you avoid the confusion with others files
% names for example f1,f2,f3...
%Save the folder of files in the current directory
path_directory='folder_name_here';
% Pls note the format of files,change it as required
original_files=dir([path_directory '/*.file_extention_format']);
for k=1:length(original_files)
filename=[path_directory '/' original_files(k).csv];
file(k)=csvread (filename);
% Next do your operation and finding
end
댓글 수: 3
KALYAN ACHARJYA
2018년 7월 26일
If your job to load all files, loop do the same. It loads the all csv files from the folder. % Next do your operation and finding outside the loop.
Guillaume
2018년 7월 26일
Note that if the files are csv files, xlsread is the slowest possible way to read these files. csvread would be much faster.
KALYAN ACHARJYA
2018년 7월 30일
Thanks @Guillaume
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!