Index exceeds matrix dimensions when using end

I got this cell array called visitcount which has four cells and each cell is an array 1st cell is 9x8 array 2nd cell is 9x8x7x6 array 3rd cell is 9x8x7x6x5x4 array 4th cell is 9x8x7x6x5x4x3x2 array
when I am trying to access the array in the 2nd cell through this line
visitcount{turn}(humanindex{1:end-1}, end)
I get "Index exceeds matrix dimensions" error
I error is caused by the bold "end" statement as I tried to remove it and put some numbers and it works no problem from 1 to 6 so end should indicate the element no 6 in this array,
humanindex is a cell array that increases according to which cell i am using to indicate the indeces according to which cell and in this case it has 4 inputs
I use MATLAB r2012a

3 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 16 日
編集済み: Azzi Abdelmalek 2012 年 12 月 16 日
What is humanindex value
Mohamed
Mohamed 2012 年 12 月 16 日
It depends on which turn so if turn is 1 then humanindex is 2x1 cell array each contains one number indicating indices, the problem occurred starting from turn = 2 at the 4D array
Jan
Jan 2012 年 12 月 16 日
Please use dots to separate the sentences.

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

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 16 日
編集済み: Azzi Abdelmalek 2012 年 12 月 16 日

0 投票

Look at this example
visitcount={rand(9,8) rand(9,8,7,6) rand(9,8,7,6,5,4) rand(9,8,7,6,5,4,3,2)};
humanindex={1 2 4 6 8};
hindex=cell2mat(humanindex)
turn=3
visitcount{turn}(hindex(1:end-1), end)
%The celllarray humanindex is causing the problem

2 件のコメント

Mohamed
Mohamed 2012 年 12 月 16 日
編集済み: Mohamed 2012 年 12 月 16 日
Well not really, there's a big error here which is that you are calling more than one element in the array which is not what I aim at I'm trying to call one element only, I am using cell array to address more than one dimension but if I convert it into matrix then it just gives me more than one value
I actually tried to index using normal indices instead of cell array and it worked but that did not solve my case as I need variable number of indices, I actually solved it using another way of indexing rather than end.
but remains the question, WHY DOES MATLAB GIVE AN ERROR?
Image Analyst
Image Analyst 2012 年 12 月 16 日
Well which ONE element to you want? You're the one who gave us the range "1:end-1" which is all rows of humanindex except for the last row. And you said "access the array in the 2nd cell" - you didn't say you wanted to access a single element of that array, you said the (whole) array.

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

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

質問済み:

2012 年 12 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by