0
我想避免for循环,我一直在阅读所有的旧帖子,但我无法解决我的问题。我是MATLAB新手,因此对我的无知表示歉意。避免与包含单元格和矩阵的循环
问题是我有一个300x2的单元格,每个单元格中有一个128x128x256矩阵。每个像素为128x128像素,每像素256通道。在300x2单元格的第一列中,我有我的平行强度值,第二列是我的垂直强度值。
我想要做的是将每个图像的每个像素(对于每个分量)并逐个通道地求和强度值。
我的代码如下:
Image_par_channels=zeros(128,128,256);
Image_per_channels=zeros(128,128,256);
Image_tot_channels=zeros(128,128,256);
for a=1:128
for b=1:128
for j=1:256
for i=1:numfiles
Image_par_channels(a,b,j)=Image_par_channels(a,b,j)+Image_cell_par_per{i,1}(a,b,j);
Image_per_channels(a,b,j)=Image_per_channels(a,b,j)+Image_cell_par_per{i,2}(a,b,j);
end
Image_tot_channels(a,b,j)=Image_par_channels(a,b,j)+2*G*Image_per_channels(a,b,j);
end
end
end
我想我可以加快速度引入(:,:,j)的,而不是指定a和b。但仍然是一个for循环。由于缺乏专业知识,我试图使用cellfun而没有取得任何成功。你能帮我一下吗?
我真的很感激它。
非常感谢,祝你有美好的一天! Ÿ