What does @m and m(:) signify here?

41 ビュー (過去 30 日間)
Siddharth Behal
Siddharth Behal 2021 年 10 月 27 日
コメント済み: Jaya 2021 年 10 月 27 日
cell2mat(cellfun(@(m)m(:),a,'uni',0))

回答 (2 件)

Star Strider
Star Strider 2021 年 10 月 27 日
Correctly stated ‘@(m)’ is a function handle (see What is a Function Handle? for details) and the ‘m(:)’ forces the argument ‘m’ to be a column vector (see MATLAB Operators and Special Characters for those details), and since ‘m’ is obviously a cell array (that can contain anything, however here appears to be numeric) —
a = {randi(9, 1, 5)} % Cell Row Vector
a = 1×1 cell array
{[2 4 3 7 7]}
out = cell2mat(cellfun(@(m)m(:),a,'uni',0)) % Array Column Vector Result
out = 5×1
2 4 3 7 7
Experiment to get diferent results.
.
  1 件のコメント
Jaya
Jaya 2021 年 10 月 27 日
Ah yes, function handle! I just forgot the word and was trying to explain in my own terms.

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


Jaya
Jaya 2021 年 10 月 27 日
編集済み: Jaya 2021 年 10 月 27 日
From what I know, @(m) specifies a function that which will be defined in terms of m. And what the function does i.e. the function description is m(:). The a is the data structure (whatever type it is) on which the the function will perform its action, m(:).
Using the above description you can take a look at the example below (from mathworks website) and make an analogy . Here the task is to extract first three characters from the str elements. Hope this helps!
str = ["Saturday","Sunday"]
str = 1×2 string array
"Saturday" "Sunday"
B = cellfun(@(x) x(1:3),str,'UniformOutput',false)
B = 1×2 cell array
{'Sat'} {'Sun'}

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by