Loop through many items in an cell array and reshape every 6 items in sequence and put them into matrices each by each
1 次查看(过去 30 天)
显示 更早的评论
My cell array "img" has over 3000 matrices in it. I want to reshape every 6 of them from 500*600 to 300,000*1, and then add them together into a 300,000*6 matrix. For now, I only know how to do it manually but processing all of them will eventually cost lots of time. I will be grateful to any looping ideas or hints or helpful links. Thank you.
Q(:,1) = reshape(cell2mat(img(1,1)),[300000 1]);
Q(:,2) = reshape(cell2mat(img(1,2)),[300000 1]);
Q(:,3) = reshape(cell2mat(img(1,3)),[300000 1]);
Q(:,4) = reshape(cell2mat(img(1,4)),[300000 1]);
Q(:,5) = reshape(cell2mat(img(1,5)),[300000 1]);
Q(:,6) = reshape(cell2mat(img(1,6)),[300000 1]);
0 个评论
采纳的回答
Matt J
2018-2-6
编辑:Matt J
2018-2-6
If speed is important, and if all of your matrices are the same size (500x600), then it was a mistake to split them across a cell array in the first place. You could have just started with a 3D array of size 500x600x3000, which would be much faster. However, if you are stuck with that situation, then you can proceed as follows:
array=cell2mat(img); %avoid this, if possible
array=reshape(array,3e5,6,[]);
Q=sum(array,3);
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!