Hey
I am facing the 'Index exceeds matrix dimensions' Error while using xlsread
[WL_time,dummy1,dummy2]=xlsread(WL_data(nn).name,1,'B8')
Its in a for loop and nn is the counter, I define 'WL_data' as
WL_data=dir('*.xlsx')
Index exceeds matrix dimensions.
Error in Unsteady_fm50hz_150sec (line 51)
[WL_time,dummy1,dummy2]=xlsread(WL_data(nn).name,1,'B8');
I would be glad if you help me

9 件のコメント

Alex Mcaulley
Alex Mcaulley 2019 年 6 月 18 日
How are you implementing the nn loop?
for nn = 1:numel(WL_data) %??
Try debugging your code putting a breakpoint inside the loop to see what is happening.
mehra
mehra 2019 年 6 月 18 日
編集済み: mehra 2019 年 6 月 18 日
for nn=1:N1;
N1 is the total number of excel files
WL_data=dir('*.xlsx');
N1=length(WL_data);
Alex Mcaulley
Alex Mcaulley 2019 年 6 月 18 日
How do you count the number of excel files? How you define N1?
mehra
mehra 2019 年 6 月 18 日
WL_data=dir('*.xlsx');
N1=length(WL_data);
Alex Mcaulley
Alex Mcaulley 2019 年 6 月 18 日
This should work. Try debugging your code to see why it is happening. Without the full code is difficult to guess it.
mehra
mehra 2019 年 6 月 18 日
編集済み: mehra 2019 年 6 月 18 日
It shows the xlsread line that makes the error
Index exceeds matrix dimensions.
Error in Unsteady_fm50hz_150sec (line 51)
[WL_time,dummy1,dummy2]=xlsread(WL_data(nn).name,1,'B8');
shall I send the code?
Alex Mcaulley
Alex Mcaulley 2019 年 6 月 18 日
At least the code inside the loop is needed to go further. It seems to be an error in
WL_data(nn).name
A simple check is to see if N1 is the total number of xlsx files in your folder.
Walter Roberson
Walter Roberson 2019 年 6 月 18 日
編集済み: Walter Roberson 2019 年 6 月 18 日
Your file loaded via load(vel_data(nn).name) contains a variable named nn that is overriding the for nn loop value
You should avoid using load without an output variable:
datastruct = load(vel_data(nn).name);
Data = datastruct.Data;
mehra
mehra 2019 年 6 月 18 日
The same error occured in
datastruct = load(vel_data(nn).name);
but this time the results show nn=16000 !!!!!

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

 採用された回答

Walter Roberson
Walter Roberson 2019 年 6 月 18 日

0 投票

vel_data=dir('*.mat');
so vel_data contains information about .mat files
WL_data=dir('*.xlsx');
so WL_data contains information about .xlsx files
N1=length(WL_data);
so N1 contains the number of WL_data which is the number of .xlsx files
for nn=1:N1;
so nn is iterating over the number of .xlsx files
load(vel_data(nn).name)
but is being used to index into the .mat files, which there might be a different number of.
You should not assume that there are equal numbers of .mat and .xlsx files, and you should not assume that they will just happen to be corresponding in order. If the name of the .xlsx should exactly match the name of the .mat then you should construct the name of the .xlsx from the .mat

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Import from MATLAB についてさらに検索

タグ

質問済み:

2019 年 6 月 18 日

回答済み:

2019 年 6 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by