How do I select non-adjacent columns in a table?

3 views (last 30 days)
Hello! I'm a first time student of Matlab so I'm sure my question is an easy one, but I can't for the life of me figure out how to do this.
I am creating a comparison function for class using a spreadsheet with only a few columns and rows. Everything must be presented in a neat table, however my textbook doesn't have any references to the 'readtable' function(or anything besides the basic xlsread) so I've been trying to learn it myself with the documentation here on this site.
I was able to get it to work when the data being compared is in columns that are adjacent to one another, however if the columns aren't touching I get this error:
Error using readtable (line 197)
Unable to determine range. Range must be of the form 'A1' (cell), 'A:B' (column-select), '1:5' (row-select), 'A1:B5'
(rectangle-select), or a valid named range in the sheet.
Error in comparison (line 32)
cars13 = readtable('carsdotcom.xlsx','Range','A1:B8,D1:D8','ReadRowNames',true);
The code I am trying to use is this:
filename = ('carsdotcom.xlsx')
cars13 = readtable('carsdotcom.xlsx','Range','A1:B8,D1:D8','ReadRowNames',true);
The error itself, makes no mention of how I should present this info correctly and the documentation here also doesn't have any examples of non-adjacent data being imported.
I'm really at my wits end here and I appreciate any insight on how to make this work. ~Heather

Accepted Answer

madhan ravi
madhan ravi on 3 Nov 2018
Edited: madhan ravi on 3 Nov 2018
T = readtable('carsdotcom.xlsx'); %EDITED
T = removevars(T,{'Chevy_1500'})
  8 Comments
Heather Kendall
Heather Kendall on 3 Nov 2018
Oh wow, you are simply the BEST!!! Thank you so so very much!!!!!! <3

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!