Info
此问题已关闭。 请重新打开它进行编辑或回答。
using Parfor instead of for
2 次查看(过去 30 天)
显示 更早的评论
Hello
I have a vector with n rows and one column.
every other row is empty and I want to fill them base on its up row and down row.
I think filling empty row are independent, then I want to use par for. Could you help me?
there is my code with common for
if true
function [ fullPath ] = fillVector( xpath,img )
tic
fullPath=zeros(2*size(xpath,1),size(xpath,2));
fullPath(2:2:end)=2*(xpath(1:1:end));
fullPath(1)=fullPath(2);
L=length(fullPath);
for i=3:2:L
switch fullPath(i+1)-fullPath(i-1)
case -2
fullPath(i)=fullPath(i-1)-1;
case -1
rowIdx=[i,i];
colIdx=[fullPath(i-1),(fullPath(i-1)-1)];
mat3Elements=img(sub2ind(size(img),rowIdx,colIdx));
[minValue,minIdx]=min(mat3Elements);
fullPath(i)=colIdx(minIdx);
case 0
rowIdx=[i,i,i];
colIdx=[fullPath(i-1),(fullPath(i-1)-1),(fullPath(i+1)+1)];
mat3Elements=img(sub2ind(size(img),rowIdx,colIdx));
[minValue,minIdx]=min(mat3Elements);
fullPath(i)=colIdx(minIdx);
case 1
rowIdx=[i,i];
colIdx=[fullPath(i-1),(fullPath(i-1)+1)];
mat3Elements=img(sub2ind(size(img),rowIdx,colIdx));
[minValue,minIdx]=min(mat3Elements);
fullPath(i)=colIdx(minIdx);
case 2
fullPath(i)= fullPath(i-1)+1;
end
end
toc
end
end
0 个评论
回答(1 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!