How to use mat2cell in splitapply?

3 ビュー (過去 30 日間)
JFz
JFz 2017 年 3 月 28 日
コメント済み: JFz 2017 年 4 月 4 日
Hi,
I used findgroup and get a G as the output. I would like to apply G to a numeric matrix (MxN) to split the matrix into several cells such that, each cell contains a smaller sized matrix (mxN).
How to write the code? I tried this but got error: Not enough input arguments. out = splitapply(mat2cell, mat, [1, 1], G); Thanks.
  1 件のコメント
Jan
Jan 2017 年 4 月 4 日
You use "mat2cell", which is a function call. Do you mean "@mat2cell", which is the function handle?

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

採用された回答

Guillaume
Guillaume 2017 年 4 月 4 日
Is
splitapply(@(m) {m}, mat, G)
what you're after?
You could do the same with mat2cell if you really wanted, it's just slightly more complicated and pointless:
splitapply(@(m) mat2cell(m, size(m,1), size(m, 2)), mat, G)
  1 件のコメント
JFz
JFz 2017 年 4 月 4 日
Thank you!

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

その他の回答 (1 件)

Sangeetha Jayaprakash
Sangeetha Jayaprakash 2017 年 4 月 4 日
編集済み: Sangeetha Jayaprakash 2017 年 4 月 4 日
I am assuming you are using the "findgroups" and "splitapply" functions to group a matrix into cells. From the error, it looks like the function "mat2cell" being applied to each group is not getting the required matrix argument.
Maybe the second format specified here to use splitapply might help:

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by