MATLAB parfor slicing issue?

好久不见. 提交于 2019-12-01 04:15:14
Jonas

As mentioned by @Chris, the line

corners(1:length(y),:,i) = [y x];

is the problem. An easy way to make sure corners is sliceable is to use a cell array

max_pts = 900;
cornerCell = cell(size(images,3),1);
parfor i = 1:size(images,3)
    I = images(:,:,i);
    [y x] = get_corners(I,max_pts);
    cornerCell{i} = [y x];
end

If you don't want corners to be a cell array (note that to plot corners for the ith image, you can call imshow(images(:,:,i),[]),hold on, plot(cornerCell{i}(:,1),cornerCell{i}(:,2),'o')), you can always convert back to your original 900-by-2-by-nImages array in a loop that won't cost you any noticeable time:

corners = zeros(max_pts,2,size(images,3));
for i=1:size(images,3)
   corners(1:size(cornerCell{i},1),:,i) = cornerCell{i};
end

First off:

  corners(1:length(y),:,i) = [y x];

That is the problem line.

Did you read the documentation?

http://www.mathworks.com/help/toolbox/distcomp/brdqtjj-1.html#bq_tcng-1

Shape of Array — In assigning to a sliced variable, the right-hand side of the assignment is not [] or '' (these operators indicate deletion of elements).

Shape of Array. A sliced variable must maintain a constant shape. The variable A shown here on either line is not sliced:

A(i,:) = []; A(end + 1) = i;

The reason A is not sliced in either case is because changing the shape of a sliced array would violate assumptions governing communication between the client and workers.

I don't have a good feel for what x and y are, but it should now be clear what the problem is. Can you rewrite this so that you aren't assigning [] to the slice?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!