# Logical Arrays and for statements

2 views (last 30 days)
Matt on 29 Oct 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

Chris A on 29 Oct 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 CommentsShowHide 1 older comment
Matt on 30 Oct 2012
actually i just realised that i dont want the variable as a double? just a logical array of 2537x357 ??