MATLAB: How to read multiple csv files with unknown size

data importfopenxlsread

I'm trying to import two csv. files into matlab. The first file is with headers, known number of columns(3), and unknown number of rows.The second file is a bit complex. The examples of them are shown in the pictures.
Note that for the second file, the format of first three rows are fixed, while the counts of Type A and type B are unknown. Type A and type B occur randomly, and for type B the header 8 does not have a value. I've tried csvread, textscan and dlmread without much luck.Any suggestions will be appreciated!

Best Answer

fid = fopen('FirstFile.csv', 'rt');
first_data_cell = textscan(fid, '%f%f%f', 'HeaderLines', 1, 'Delimiter', ',', 'CollectOutput', 1);
fclose(fid);
first_data = first_data_cell{1};
%
fid = fopen('SecondFile.csv', 'rt');
second_data_cell = textscan(fid, '%s%f%f%f%f%f%f', 'HeaderLines', 4, 'Delimiter', ',', 'CollectOutput', 1);
fclose(fid);
second_data_col1 = second_data_cell{1};
second_data_rest = second_data_cell{2};
The "missing" numeric values will be replaced by NaN by default.