Assign excel data to multi-dimensional array

Hi I want to assign data repetitively in an excel spreadsheet to a n*n*5 dimensional array, ie 5 pages.
% User inputs
ExcelFile = '\InputData.xlsx';
SheetNumber = 1;
InputDataRange = 'B5:Y910';
[alldata, text, ~] = xlsread(ExcelFile, SheetNumber, InputDataRange);
data=alldata(:,:,1)
data=alldata(:,:,2)
data=alldata(:,:,n)
data=alldata(:,:,5).....etc
I get an error message stating "Index exceeds matrix dimensions."
Any ideas? Regards

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 7 月 22 日
編集済み: Azzi Abdelmalek 2014 年 7 月 22 日

0 投票

Change this line (alldata should be the third output argument)
[~,text,alldata] = xlsread(ExcelFile, SheetNumber, InputDataRange);

7 件のコメント

bugatti79
bugatti79 2014 年 7 月 22 日
Hi Azzi,
Im afraid that does not work, still get the same error...
bugatti79
bugatti79 2014 年 7 月 22 日
For my original script, it seems that each entry read in from excel is in a square bracket...
bugatti79
bugatti79 2014 年 7 月 22 日
I thought changing alldata from a cell to an array might work still getting the same error
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 7 月 22 日
What the size of alldata? type
size(alldata)
bugatti79
bugatti79 2014 年 7 月 22 日
ans
906 24
bugatti79
bugatti79 2014 年 7 月 22 日
I think this might work
[~,text,alldata] = xlsread(ExcelFile, SheetNumber, InputDataRange);
datacell=alldata(:,:);
dataarray = cell2mat(datacell);
data=dataarray;
data(:,:,2)=dataarray;
data(:,:,3)=dataarray;
data(:,:,4)=dataarray;
data(:,:,5)=dataarray;
Mevlut K
Mevlut K 2020 年 12 月 26 日
Hi Azzi
I have seen so many post from you on the Matlab discussion forum. I had a question, that i cannot solve. Do you have any possibility to see that. I share the screenshot from the error.

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

質問済み:

2014 年 7 月 22 日

コメント済み:

2020 年 12 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by