Indexed Assignment on the Right Side
조회 수: 2 (최근 30일)
이전 댓글 표시
I am calling function f(x) that returns a matrix of 100 columns.
All what I need is just the 10th column. So I need one vector from the whole returned matrix.
I need to get rid of 99 columns and retain only the 10th column.
In Julia, this can be done by:
columnTen = f(x)[:,10]
I am dying to do the same thing in MATLAB.
Not sure why this simple operation seems impossible.
댓글 수: 0
채택된 답변
Walter Roberson
2020년 11월 17일
columnTen = struct('fx', rand(7,20)).fx(:,10) %needs R2019b or later IIRC
columnTen = subsref(rand(7,20), substruct('()', {':', 10}))
But if you are permitted an initialization beforehand:
Col = @(M,n) M(:,n); %once
ColumnTen = Col(rand(7,20), 10)
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!