Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
using Parfor instead of for
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!