I am using xlsread as such:
subset = xlsread(filename, sheet, xlRange)
In particular:
filename = 'nameF';
sheet = 'sheet1';
xlRange = 'A1'; % I use one column to cover or using sheet and xlRange together
subsetA = xlsread(filename, sheet, xlRange)
I get this:
subsetA =
[]
Same result when I use xlRange = 'A1:B1'
The purpose is to select particular columns from that sheetX of WorkbookY. Any recommendation?
Thank you
Eleftheria

 채택된 답변

OCDER
OCDER 2017년 9월 15일
편집: OCDER 2017년 9월 15일

1 개 추천

Looks like your excel file has nothing but string data, hence the 1st output of xlsread will give you empty (no numeric data to show). Here's more info on xlsread .
Try the following, and use the data you need:
[NumData, TextData, AllData] = xlsread(filename, sheet, xlRange)
Also, A1:B1 will only select the 1st row of A to B. Use xlRange = 'A:B' to select the A and B columns instead.

댓글 수: 3

Thank you Donald, there was a string starting my file that I was unaware.
Is it possible xlRange be a vector, e.g. xlRange = [1 2 4 20 30]?
Thank you again
OCDER
OCDER 2017년 9월 15일
편집: OCDER 2017년 9월 15일
I don't think you can do this, although it'd be a nice feature. Based on the document, xlRange must specify a "Rectangular range, specified as a character vector or a string."
So a workaround would be to load everything, and then select what you want.
[~, ~, AllData] = xlsread(filename, sheet);
AllData = AllData(:, xlRange);
Good idea and it works. Thank you Eleftheria

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Riffat Mughal
Riffat Mughal 2021년 12월 31일

0 개 추천

Hi,
I wanted to import data using xlsread command from each sheet (There are 750 sheets). In range I wanted to import data from selected columns let's suppose from E to M. In each sheet number of rows are different.
Can you please assist me how I can import data from each row using xlsread command.

댓글 수: 4

Walter Roberson
Walter Roberson 2021년 12월 31일
Is there a reason you have not switched to readtable() or readmatrix()?
Riffat Mughal
Riffat Mughal 2021년 12월 31일
Yes, because I'm working on Treasury bonds for which dates are important. Extracting data using readtable command is creating problem with the date variables.
Walter Roberson
Walter Roberson 2021년 12월 31일
Which MATLAB release are you using? readtable does a pretty good job on dates as datetime objects. Sometimes you need to setvaropts to set input format though. Can you attach about 3 rows from one of the tables for testing?
Riffat Mughal
Riffat Mughal 2021년 12월 31일
Please find attached the requested file.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

태그

질문:

2017년 9월 15일

댓글:

2021년 12월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by