cellfun with Frobenius norm
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Xh Du
el 3 de Mzo. de 2017
Comentada: Xh Du
el 3 de Mzo. de 2017
Hi all,
I'd like to obtain Frobenius norm for each element in a cell, I wrote this:
a1 = (1:6)';
a2 = (2:7)';
a3 = (3:8)';
a = {a1 a2 a3};
nm.a = cellfun(@norm, a);
However, if I want a Frobenius norm, I'll need norm(x, 'fro'), how can I add 'fro' in this case in cellfun?
Thank you!
0 comentarios
Respuesta aceptada
Guillaume
el 3 de Mzo. de 2017
Use an anonymous function:
nm.a = cellfun(@(m) norm(m, 'fro'), a)
3 comentarios
Guillaume
el 3 de Mzo. de 2017
Looks compact enough to me. If it bothers you that much, create an m file called frobeniusnorm.m with the content:
function m = frobeniusnorm(x)
m = norm(x, 'fro');
end
You can then write your cellfun more compactly:
nm.a = cellfun(@frobeniusnorm, a);
Más respuestas (0)
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!