Effacer les filtres
Effacer les filtres

How to use svd in cellfun?

1 vue (au cours des 30 derniers jours)
Xh Du
Xh Du le 5 Jan 2017
Commenté : Adam le 5 Jan 2017
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!

Réponse acceptée

Adam
Adam le 5 Jan 2017
Modifié(e) : Adam le 5 Jan 2017
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 commentaires
Xh Du
Xh Du le 5 Jan 2017
Wow, thanks!
Adam
Adam le 5 Jan 2017
Ah, yes, I keep forgetting that, I'm so used to just wrapping things in anonymous functions!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Eigenvalues dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by