如何给Cell中的每​个元素reshape​(不想用for)。

由于我要用eig函数,所以以前数据结构中cell的每个元素是1X9的矩阵,必须reshape成3X3的矩阵,然后使用cellfun就安逸了。
使用for循环,肯定可以。但是由于数据很多,大概10w+个,效率很低。不知道cellfun能支持reshape函数么?
有经验的大大,求助啊!
现在的解决方案是:
for i=1:ngp
gp_C_cell{i,1} = reshape(gp_C_cell{i,1},3,3)';
end

 채택된 답변

0 개 추천

用 cellfun 可以实现, 举个例子把:
A = {rand(1,9),rand(1,9),rand(1,9)}
cellfun(@(x) reshape(x, 3, 3).', A, 'UniformOutput', false)

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!