필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

using Parfor instead of for

조회 수: 2 (최근 30일)
bkshn
bkshn 2015년 1월 8일
마감: MATLAB Answer Bot 2021년 8월 20일
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

답변 (1개)

Stalin Samuel
Stalin Samuel 2015년 1월 8일

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by