xlsread returning empty only sometimes

4 ビュー (過去 30 日間)
Mathieu Lebiere
Mathieu Lebiere 2018 年 12 月 4 日
コメント済み: Walter Roberson 2018 年 12 月 5 日
I am having trouble with xlsread actually returning values. This code is in a for loop with i as the iterating variable.
sheet = strcat(num2str(i), ' in');
file = 'data.xlsx';
times_data = xlsread(file,sheet,'A3:A402');
Data1 = xlsread(file,sheet,'B3:B402');
Data2 = xlsread(file,sheet,'F3:F402');
Data3 = xlsread(file,sheet,'J3:J402');
Data4 = xlsread(file,sheet,'N3:N402');
Data5 = xlsread(file,sheet,'R3:R402');
In the code above only Data5 has anything stored in it. In the "Workspace" tab everything else is show as empty( with a [] symbol). Does anyone know why this may be and a way to fix it?
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 12 月 5 日
What is your value for i ?
My testing with your file on Mac does not show anything unusual for the sheets that are present.
Mathieu Lebiere
Mathieu Lebiere 2018 年 12 月 5 日
i goes between 0.5 and 4 in increments of 0.5. It is part of a for loop. I did not get any errors when running the code either on windows.

サインインしてコメントする。

採用された回答

Cris LaPierre
Cris LaPierre 2018 年 12 月 5 日
Any chance you can attach one of your spreadsheets? Much easier to debug that way.
Without seeing that, I'd have two guesses:
  1. Data1-4 and times_data are empty because there is no data in the specified range
  2. The data entered in those ranges is not numeric. In this case, you want to use the [num,txt,raw] = xlsread(___) syntax. You can read more in the xlsread documentation page.
  6 件のコメント
Mathieu Lebiere
Mathieu Lebiere 2018 年 12 月 5 日
Much appreciated!
Walter Roberson
Walter Roberson 2018 年 12 月 5 日
On Mac the values were read properly . That suggests that adding the option 'basic' might have worked on Windows .

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by