Logical Arrays and for statements

1 Ansicht (letzte 30 Tage)
Matt
Matt am 29 Okt. 2012
My issue is the line commented. To make that line work CNccm needs to be a logical array the size of 2537*357. At the moment i am just getting a 2537*1 array, So over every loop it over writes the value. So basically at the end of the loop i expect to get a 357*1 matrix with values ranging between 0 and 1. Im really stuck if i individually put in values for i when calculating the CNccm value it works fine its just not working with the loop. can someone pleeeease help im getting desperate.
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);
r = transpose(srt(21,1:357));
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);
CNccm = (rcontr(:,i)) <= r(i,1); %Need to make a [2537*357] Logical array
Nccm(i) = sum(CNccm);
Prob(i)= 1-((Nccm(i)/20)*(9/81));
hold on
end

Antworten (1)

Chris A
Chris A am 29 Okt. 2012
See if this works:
CNccm(i,:) = transpose((rcontr(:,i)) <= r(i,1)); % Need to make a
% [2537*357] Logical array
Nccm(i) = sum(CNccm(i,:));
  2 Kommentare
Matt
Matt am 30 Okt. 2012
it has given me the answer in type double which is a massive help thanks.. but something is still not going right and i dont understand why.. i should get for Nccm a list of integer numbers ranging in size (Nccm counts up the number if 1's in CNccm) however i get zero for about 337 values then numbers from 338-357 I dont know why its doing this?? if i put a value of 1 in for i and do the calculation manually i get a non zero value.. the error is occuring somewhere in the two above lines..
Matt
Matt am 30 Okt. 2012
actually i just realised that i dont want the variable as a double? just a logical array of 2537x357 ??

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by