How can I import data from my .csv file, from specific rows and columns, into a matrix?
Show older comments
I would like to read only the data that is highlited into a variable. I will be using this script to read data from hundreds of identically formatted .csv files, except they are not all the same length (i.e. some of them have more or less rows of collected data). The header formatting is the same for all of them though. Thank you!

3 Comments
dpb
on 2 Jul 2019
Just read the file with 'headerlines',15 if you want the column variable headings or 16 if not, then just save the 3rd thru end columns.
Much faster to just make the read as simple as possible and do the (in this case minimal) cleanup in memory.
data=readtable('yourfile.ext','headerlines',16); % presume don't want headers
data=data{:,3:end}; % save to a regular array
Alternatively, use detectImportOptions and create an import object that specifies the variables wanted or revert to old textscan and specific format to skip the two columns.
cag
on 2 Jul 2019
Christine Nie
on 15 Oct 2020
Worked quite well! Thank you!
Answers (1)
Sulaymon Eshkabilov
on 2 Jul 2019
An alternative way is:
ALL = csvread('raw_data.csv');
Data = ALL(3:end, :);
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!