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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by