Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如考虑函数“规范”。我有一个矩阵,我想将“范数”应用于矩阵中的每一行,并获取该矩阵中每一行的所有范数的向量。
我希望我能做 norm(A, 'rows'),但那是不可能的。还有其他方法吗?
您可以在不转换为元胞数组的情况下执行此操作:
arrayfun(@(n) norm(A(n,:)), 1:size(A,1))
像这样?
M = 1e4; N = 1e3; A = randn(M, N); % Solve B = mat2cell(A, ones(M, 1), N); b = cellfun(@norm, B);
也许可以使用 arrayfun 代替?