필터 지우기
필터 지우기

Info

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

help with this loop

조회 수: 1 (최근 30일)
Matt
Matt 2012년 10월 29일
마감: MATLAB Answer Bot 2021년 8월 20일
Ok this is basically the code im trying to run. the basic jist is that it calculates the distance to all other points, then compares to a control field, calculates how many points are within that distance (in this case the radius of a circle). With this number i then want to calculate the probability (the final bit of the code after end(k)) this is where the problem is i think. If i individually put in values for i the code works, but im dealing with large data sets and its not really practice to individually in put 1-357 each time. When i run the loop however it doesnt work so im guess my issue is with the loop. can anyone help me out?
rccm = zeros(357,357);
Crccm = zeros(357,2537);
CNccm = zeros(357,2537);
Nccm = zeros(2537,1);
Prob = zeros(357,1);
for i=1:1:357
for j=1:1:357;
rccm(i,j) = sqrt((0.5*(jmag(i,1)-jmag(j,1)).^2)+((diffmag(i,1)-diffmag(j,1)).^2)+((diffmag2(i,1)-diffmag2(j,1)).^2));
hold on
end
srt = sort(rccm); %Put in value of the 15th star
r = transpose(srt(21,1:1:357)); %Radius of the 21 star
for k=1:1:2537;
Crccm(i,k) = sqrt((0.5*(jmag(i,1)-Cfjmag(k,1)).^2)+((diffmag(i,1)-Cfdiffmag(k,1)).^2)+((diffmag2(i,1)-Cfdiffmag2(k,1)).^2));
end
rcontr = transpose(Crccm);
%rcontr1 = sort(rcontr);
CNccm = rcontr(:,i) <= r(i,1); %rcontr = Crccm
Nccm(i) = sum(CNccm(1:2537,1));
Prob(i) = 1-((Nccm(i)/20)*(9/81));
hold on
end
  댓글 수: 3
Matt
Matt 2012년 10월 29일
they are all just different variables of type double. basically im expecting to get values between 0 and 1 for the probability for some reason i get values of 1 for everything except i values of 338-357 which doesnt make sense because when i put an i value of 1 in manually for example i get a non zero value
Matt
Matt 2012년 10월 29일
the main issue i think is the
CNccm = rcontr(:,i) <= r(i,1);
i need CNccm to be a logical of size 2537x357
but at the moment its 2537x1 so with every loop it overwrites the previous logical array. If i can get it as a matrix then i can simply just use a value for i to sum each column. How do i create a logical array which contains all of the results for every loop?

답변 (0개)

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

Community Treasure Hunt

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

Start Hunting!

Translated by