필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

i want to reduce the use of repeated for loops as i explained below???

조회 수: 1 (최근 30일)
M.Prasanna kumar
M.Prasanna kumar 2019년 8월 22일
마감: Stephen23 2019년 8월 22일
when SS =1 , KK loop should not take the value from 1 to 3
when SS = 2:23 , KK loop should not run for SS-1:SS+1
when SS =24 , KK loop should not take the value from 22 to 24
to calculate the vraible "dist" i used three sets of for loops. is it possible to reduce
I am able to get the answer but i dont want to repeat the same code for three times. how to resolve the problem???
for ss = 1
for kk = setdiff(1:no_receivers+1,1:3)
for ii = 1:no_gridsx
dist(ii,1:250,kk,ss) = sqrt((apert_x(1,ss)-X(ii,1:250)).^2+(apert_y(1,ss)-Y(ii,1:250)).^2)+sqrt((X(ii,1:250)-apert_x(1,kk)).^2+(Y(ii,1:250)-apert_y(1,kk)).^2);
end
end
end
for ss = 2:23
for kk = setdiff(1:no_receivers+1,ss-1:ss+1)
for ii = 1:no_gridsx
dist(ii,1:250,kk,ss) = sqrt((apert_x(1,ss)-X(ii,1:250)).^2+(apert_y(1,ss)-Y(ii,1:250)).^2)+sqrt((X(ii,1:250)-apert_x(1,kk)).^2+(Y(ii,1:250)-apert_y(1,kk)).^2);
end
end
end
for ss = 24
for kk = setdiff(1:no_receivers+1,22:24)
for ii = 1:no_gridsx
dist(ii,1:250,kk,ss) = sqrt((apert_x(1,ss)-X(ii,1:250)).^2+(apert_y(1,ss)-Y(ii,1:250)).^2)+sqrt((X(ii,1:250)-apert_x(1,kk)).^2+(Y(ii,1:250)-apert_y(1,kk)).^2);
end
end
end

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by