user input for xlsread

5 views (last 30 days)
Neha
Neha on 10 Feb 2014
Answered: ES on 11 Feb 2014
Hi,
I am trying to implement code where the user is asked to choose the range of data they want to import from excel. Here is what I have so far:
clc, clear, close all
[baseFileName, folder]=uigetfile('*.xl*','Specify an Excel file');
fullFileName=fullfile(folder,baseFileName);
[totalRange]=xlsread(fullFileName,-1)
xpos=totalRange(:,2);
track=totalRange(:,1);
frame=totalRange(:,3);
And this is the error I received:
Attempted to access totalRange(:,2); index out of bounds because
size(totalRange)=[65,1].
Error in userxlsread (line 5)
xpos=totalRange(:,2);
Note: In the Excel spreadsheet, the columns that contain the data the user wants are not necessarily adjacent to each other.
When I try the code with columns that are right next to each other, it works. However I would like to get it to work so that the columns of data do not have to be right next to each other.
Thank you.

Answers (1)

ES
ES on 11 Feb 2014
I tried. Supposedly, xlsread with -1 as parameter only reads the adjacent columns. If you choose columns that are not adjacent, it picks only the adjacent columns. Same with the case of rows too.
You might either read the full file and truncate the data as per User's choice.

Community Treasure Hunt

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

Start Hunting!