Hello everybody,
I have to import data from multiple csv files (more than 4000). Each csv file contains 7 columns, between 1 and 6 rows and 1 header-line. It contains multiple types of data, this format : formatSpec = '%f %f %f %s %f %f %f'. I used this to extract the data :
%%How many file ?
files = dir('C:\Users\titin\Documents\MATLAB\UALG\RADAR07\*csv');num_files = length(files);%%Extract data from files
for i=1:num_filesfor j=1:1% open files
fid = fopen(files(i).name% read data from csv file
readData = textscan(fid,'%f %f %f %s %f %f %f','HeaderLines',1,'Delimiter',',','TextType','string','ReturnOnError',false,'EndOfLine','\r\n');% extract data from readData
UserID(i,j) = readData(1,1); Longitude(i,j) = readData(1,2); Latitude(i,j) = readData(1,3); Timestamp(i,j) = readData(1,4); SpeedOverGround(i,j) = readData(1,5); NavigationStatus(i,j) = readData(1,6); ShipType(i,j) = readData(1,7);endend
The problem is, when I have a csv file which have more than 1 rows it creates a cell into an another cell like this :
For the numeric cell its not a problem because I used the function : cell2mat, and each cell was divided. But for the string cell, I don't know how to proceed to not have cells into cells. I tried to use the function cellstr but when there is a cell into cell I have an error.
If someone can help it would be great !
Thanks !
Best Answer