Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

using Parfor instead of for

2 visualizzazioni (ultimi 30 giorni)
bkshn
bkshn il 8 Gen 2015
Chiuso: MATLAB Answer Bot il 20 Ago 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

Risposte (1)

Stalin Samuel
Stalin Samuel il 8 Gen 2015

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by