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

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

T = readtable('carsdotcom.xlsx'); %EDITED
T = removevars(T,{'Chevy_1500'})

8 Comments

If I use this, it will include column C which is what I'm trying to avoid. Is it not possible to do a table that is not a complete square?
You could import and then do something like extracting from the data
I tried doing that using code examples from this doc, but again there was nothing given that was no adjacent and when I tried to make it work, I got errors. Can you be more specific about 'extracting'?
Upload the file so that I could try and let you know :)
I hope this works:
https://drive.google.com/open?id=1EZBpdblyGskgsS7T8Q_7JkRqgq4fWK71 ^link for the code
https://drive.google.com/open?id=1Qa95zJw-KD05LJduEreLGmcVdwc15ori ^link for the spreadsheet
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!