user input for xlsread

조회 수: 7 (최근 30일)
Neha
Neha 2014년 2월 10일
답변: ES 2014년 2월 11일
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.

답변 (1개)

ES
ES 2014년 2월 11일
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.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by