Logical Arrays and for statements
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Chris A
2012-10-29
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,:));
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!