how to split the data in for loop?

1 次查看(过去 30 天)
Sierra
Sierra 2022-10-22
回答: Alex Hanes 2022-10-24
inter_point = [];
idx = [];
tic
parfor k = 1:length(x1)
for i = 1:length(Arr_1516)
for j = 1:length(Arr_1516(i).Longitude)-1
p1 = [x1(k),y1(k)];
p2= [x2(k),y2(k)];
L1 = [Arr_1516(i).Longitude(j), Arr_1516(i).Longitude(j+1);
Arr_1516(i).Latitude(j), Arr_1516(i).Latitude(j+1)]; % Line 1 : Mean Trajectory
L2=[p1(1,1),p2(1,1);p1(1,2),p2(1,2)]; % Line 2 : Line
inter = InterX(L2,L1);
if isempty(inter)
idx=[idx;i];
continue
end % if
inter = [inter(1,1),inter(2,1)];
inter_point = [inter_point;inter];
end % j
end % k
end % i
toc
I want to split the data when k is moving to next number.
I tried with this code to inster NaN NaN. but it didnt work at all
inter_point = [inter_point;inter;NaN NaN];

回答(1 个)

Alex Hanes
Alex Hanes 2022-10-24
It looks like your issue is because your parfor loop violates the following static condition:
Required (static): If you use a nested for-loop to index into a sliced array, you cannot use that array elsewhere in the parfor-loop.
You can see the requirements on this page: https://www.mathworks.com/help/parallel-computing/nested-parfor-loops-and-for-loops.html

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by