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