How do I import this simple CSV? Should I use textscan or something else?
2 views (last 30 days)
Show older comments
Daniel Bridges
on 22 Jan 2018
Commented: Daniel Bridges
on 23 Jan 2018
I am struggling to import data in MATLAB. The following code creates a 1x11 cell array with cells containing 0x0 char or NaN arrays, clearly wrong.
filepath = 'easy.csv';
% First we scan the file to see how many rows of data it has.
rows = 3; columns = 3;
RepetitionNumber = rows*columns;
% We construct the format spec based on this number of rows and columns.
formatSpec = ['%*s %*s %*s %*s %q %q',repmat('%f',[1,RepetitionNumber])];
% We read the file using textscan.
fileID = fopen(filepath);
DVH = textscan(fileID,formatSpec,'Delimiter',{',' '/n'});
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!