How to take a part of matrix, which is function result?

2 ビュー (過去 30 日間)
Junho Kweon
Junho Kweon 2018 年 9 月 5 日
コメント済み: Junho Kweon 2018 年 9 月 5 日
My code is like this.
A = [1 2; 3 4];
B = sum(A) % I want to use fft or other functions rather than 'sum'
x = B(1)
Then, the result is
B = 4 6
x = 4
If I want to take part of the function directly, that is like
x = sum(A)(1)
How can I do it?

採用された回答

Walter Roberson
Walter Roberson 2018 年 9 月 5 日
Nth = @(M, varargin) M(varargin{:});
After which you can
x = Nth(sum(A), 1);
There is no syntax for indexing the result of a function: there is only a way to use an auxillary function to express the indexing in expression form instead of having to always assign to a temporary variable and index that variable.
  1 件のコメント
Junho Kweon
Junho Kweon 2018 年 9 月 5 日
OMG, that's such an easy way! Thanks pal :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by