# Indexing via 3d array changed behaviour 2015a -> 2015b?

조회 수: 2(최근 30일)
Sven 2015년 10월 15일
댓글: Scott French 2015년 10월 21일
Hi all, just got 2015b, here's a strange one where indexing via a multidimensional array has a differently shaped output to previous versions:
Code:
a = 1:10;
b = reshape(4:6,1,1,[]);
a(b)
2015a and before:
ans(:,:,1) =
4
ans(:,:,2) =
5
ans(:,:,3) =
6
2015b:
ans =
4 5 6
I searched through the release notes and couldn't find anything that relates to this behaviour change. Did I miss something? Or is this a bug that I should report?
##### 댓글 수: 1표시숨기기 없음
David Young 2015년 10월 15일
I really hope someone answers this! It's very worrying that something as fundamental as array indexing might have quietly changed between versions. Of course the underlying problem is the inconsistent way indexing is applied to A(B) if both A and B are vectors. Since in this case isvector(b) returns 0, I think that the pre-2015b results are "correct", so to me it looks like a bug.

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

### 채택된 답변

Scott French 2015년 10월 20일
This was an intentional change/bug fix. Prior to R2015b, there was an inconsistency in the MATLAB indexing behavior - if you try your experiment in R2015a, but with the value of "a" being stored in a field of a struct, or an element of a cell, you'd get a different answer:
>> s.a = 1:10
s =
a: [1 2 3 4 5 6 7 8 9 10]
>> b=reshape(4:6, 1, 1, []);
>> s.a(b)
ans =
4 5 6
It didn't seem reasonable that the same value could be indexed by the same index, but give different results depending on where the value came from. So we changed it to give the same result.
The rule that we apply is, for an expression R(I) where R and I both have only one non-singleton dimension, then the dimensions of the result have the length of I, and the orientation of R.
Scott
##### 댓글 수: 5표시숨기기 이전 댓글 수: 4
Scott French 2015년 10월 21일
Ramble cheerfully accepted.

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

### 범주

Find more on Loops and Conditional Statements in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by