What do brackets mean in this expression, y(Z)?

조회 수: 1 (최근 30일)
Wallace Yang
Wallace Yang 2015년 2월 6일
댓글: Wallace Yang 2020년 10월 26일
>>%Hi:
>>y = [1; 2; 3; 1; 2; 3; 1; 2; 3];
>>Z=[1 1 2; 2 1 1; 1 1 4];
>>y(Z)
ans =
1 1 2
2 1 1
1 1 1
>>%But I have no idea what the () operation is. I see it in some code that I'm trying to figure out. Thanks.
>>Wallace

채택된 답변

Jason Moore
Jason Moore 2015년 2월 6일
편집: Jason Moore 2015년 2월 6일
In this case Z is being used to reference the y array. Since Z is also an array, for each value of Z the y array will be referenced and will return the corresponding value in y. Therefore, the result of this command will also be an array the size of Z
i.e. the first row of your Z array is 1 1 2 So when used in the following command MATLAB is actually returning y(1),y(1),y(2) for your first row of data
  댓글 수: 3
Isaiah Naranjo
Isaiah Naranjo 2020년 10월 17일
What about the last row?
1 1 1
i can see where y returns y(1),y(1),y(2) for the first row what about the second?
and mainly the third row? where its 1 1 1 instead 1 1 4?
Wallace Yang
Wallace Yang 2020년 10월 26일
The last row consists of the 1st element, the 1st element, and the 4th element of the y array (in this case, also a 1).

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by