Info

This question is closed. Reopen it to edit or answer.

using Parfor instead of for

1 view (last 30 days)
bkshn
bkshn on 8 Jan 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
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

Answers (1)

Stalin Samuel
Stalin Samuel on 8 Jan 2015

Community Treasure Hunt

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

Start Hunting!