Hello,
I'd like to use svd in cellfun. Imagine a multidimensional cell like this:
inst = cell(1, 3, 5, 2);
inst(:,:,1,1) =
[308x21 double] [308x21 double] [308x21 double]
Each element of inst is a 308*21 double. Now I'd like to apply SVD on each element of inst to extract the singular values, so I write this:
instsvd = cellfun(svd, inst, 'UniformOutput', false);
MATLAB gives me error:
Error using svd
Not enough input arguments.
Any idea how to solve this?
Many thanks!

 채택된 답변

Adam
Adam 2017년 1월 5일
편집: Adam 2017년 1월 5일

0 개 추천

instsvd = cellfun(@(x) svd(x), inst, 'UniformOutput', false);
The first argument to cellfun should be a function handle, you are passing the name of a function instead, with no arguments. The above should work and is using an anonymous function where 'x' is a placeholder for each of the elements of your cell array in turn.

댓글 수: 3

FYI for this case you could simplify the code just a little bit by using a regular function handle to svd rather than creating an anonymous function.
instsvd = cellfun(@svd, inst, 'UniformOutput', false);
Xh Du
Xh Du 2017년 1월 5일
Wow, thanks!
Adam
Adam 2017년 1월 5일
Ah, yes, I keep forgetting that, I'm so used to just wrapping things in anonymous functions!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2017년 1월 5일

댓글:

2017년 1월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by