Say I have D = D(somevector);
and A = A(:,somevector);
Does the former make this a column? What is it doing if not? Does the latter make a matrix A in some arrangement?
Please provide a link to where I can read more about this. I have been web surfing for too long.
Cheers, Neo!

 채택된 답변

James Tursa
James Tursa 2016년 2월 2일
편집: James Tursa 2016년 2월 2일

0 개 추천

See the link on indexing:
In particular, if you supply only one subscript as in your first example, then MATLAB will use what is known as "Linear Indexing" in the link, and give you a column vector as a result with the elements being composed of the linear indexed elements you specified with somevector.
In your second example, you supplied two indexes. The result will be a sub-matrix composed of all the rows (via the : supplied for the first index), and the columns supplied by your somevector.

댓글 수: 3

The first syntax
D = D(somevector)
would typically be used for either selecting only a portion of D, or for re-arranging D. For example,
D = D([3 1 2])
would be the same as
D = [D(3), D(1), D(2)]
(except that it has some subtle issues about whether a row vector or column vector is produced.)
Occasionally, not often, you might see the same subscript repeated, like
D = D([1 1 1])
This is making copies of that element, like [D(1), D(1), D(1)], which would be like repmat(D(1),1,3) . Indeed, repmat() is programmed by repeated subscripts.
Neo
Neo 2016년 2월 3일
Thanks Walter. I would've accepted your answer but you left it as a comment!
-Cheers Neo
Neo
Neo 2016년 2월 3일
Thanks James!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

질문:

Neo
2016년 2월 2일

댓글:

Neo
2016년 2월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by