Matlab multiplied iterator for array index inside parfor - slicing

拟墨画扇 提交于 2020-01-03 03:57:08

问题


Is it possible to slice 3'rd line (tt)? This code is simplified, but the problem is similar. I am using multiplied iterator (3*i) in array index, however it doesn't work. Maybe it is possible to change it somehow.

parfor i = 1 : NE      
   tmp = i * [1, -1; -1, 1];                 
   tt(3*i-1:3*i+1) = tmp([3,2,4]);          
   pp(i) = tmp(1,1,i);   
end;

Thanks :)


回答1:


To be a sliced output variable, tt must be indexed using literally only the loop variable i, and other constant terms (including :). Perhaps you can make tt rectangular, and assign a whole column at a time, and then reshape later, something like this:

tt = zeros(3, 10);  
parfor ii = 1:10
  tt(:, ii) = [ii; ii; ii];
end
tt = reshape(tt, 1, numel(tt));


来源:https://stackoverflow.com/questions/15777241/matlab-multiplied-iterator-for-array-index-inside-parfor-slicing

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