MATLAB: Readmatrix non-adjacent columns

importing excel datamatrix

I would like to import 3 columns of a excel/csv file into a matrix. The columns I want are non-adjacent (Columns C, P, Q). I can import all the columns between C-Q adjacent columns like:
M=readmatrix('file.csv', 'Range', 'C:Q' );
However, I don't wan't columns D-O. I try things like this and it doesn't work.
M=readmatrix('file.csv', 'Range', 'C:C, C:Q' );
How do I only import the 3 colmns C, P, Q into 1 matrix?

Best Answer

readmatrix accepts import options generated with detectImportOptions. You can use selectedVariables option to indicate which variables to read.
https://www.mathworks.com/help/matlab/ref/matlab.io.spreadsheet.spreadsheetimportoptions.html#bvetiw8-1_sep_shared-SelectedVariableNames
Related Question