Subscript indices must either be real positive integers or logicals. New to MATLAB please help me out.
1 回表示 (過去 30 日間)
古いコメントを表示
clc;
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 25;
figure;
imshow('pc3.png');
hold on
hold on
%legend('Relay', 'Sink', 'Sensor');
%
x1 = [105,107,58,58,75,146,118,18,48,55,108,80,80];
y1 = [190,280,190,280,145,153,103,153,103,65,65,50,10];
hold on
A=100;
B=140;
plot(A,B, 'mo-', 'MarkerSize', 10,'LineWidth', 2);
hold on
% Make 75 points in set #2
Xmin = 60;
Xmax = 99;
x2 = Xmin+rand(1,50)*(Xmax-Xmin);
Ymin = 10;
Ymax= 260;
y2 = Ymin+rand(1,50)*(Ymax-Ymin);
plot(x2, y2, 'b*');
%numPoints2 = 50;
%x2 = 167*rand(numPoints2, 1);
%y2 = 302*rand(numPoints2, 1);
% Plot set 1 in red
plot(x1, y1, 'r.', 'MarkerSize', 13);
% Plot set 2 in blue
hold on;
plot(x2, y2, 'b*', 'MarkerSize', 5);
grid on;
for i=1:13
for j=1:50
%Find distances between every point in set 1 to every point in set #2.
distances(i,j) = pdist2([x1(i),y1(i)], [x2(j), y2(j)], 'euclidean');
end
minDistance(i) = min(distances(i,:));
end
% Find min distance
disp (distances);
dist1 = sqrt((x2-A).^2+(y2-B).^2)
%disp (dist1);
dist2 =sqrt((x1-A).^2+(y1-B).^2)
disp (minDistance);
a=1:40;
for i = 1:10
pop(i,:) = a(randperm(numel(a),10))
end
for i = 1:10
opo_pop(i,:) = 40-pop(i,:)
end
%Est(13,5)=zeros();
%for i=1:13
% b=1;
%for k=1:50
%for j=10*k-9:10*k
%if mod(k,10)==0
%b=b+1;
%end
s=250;
Et=16.7;
Eamp=1.97;
N=10;
data_agg=1;
Er = 36.1;
d0=30;
c=10;
for k = 1:13
for j = 1:10
for i = 1:10
Ets(k,j,i)=s*(Et+Eamp*(distances(k,pop(j,i)).^2));
%Es(i,b)=Est(i,b)+Et(i,k);
end
end
end
disp (Ets);
for k = 1:13
for j = 1:10
for i = 1:10
OEts(k,j,i)=s*(Et+Eamp*(distances(k,opo_pop(j,i)).^2));
%Es(i,b)=Est(i,b)+Et(i,k);
end
end
end
disp (OEts);
%not able to get the output
1 件のコメント
採用された回答
Jan
2018 年 12 月 6 日
編集済み: Jan
2018 年 12 月 6 日
With some guessing:
a = 1:40;
for i = 1:10
pop(i,:) = a(randperm(numel(a),10))
end
for i = 1:10
opo_pop(i,:) = 40 - pop(i,:)
end
If a is between 1 and 40 and you calculate 40 - pop, the result opo_pop is between 0 and 39. Then:
distances(k,opo_pop(j,i))
will fail, if a 0 is found, because Matlab's indices start at 1. Solution:
opo_pop(i,:) = 41 - pop(i,:)
Now opo_pop is between 1 and 40 also.
3 件のコメント
Jan
2018 年 12 月 7 日
Please apply a proper formatting of teh code. This is easy: select the code with the mouse and press teh button for code formatting in teh bar on top of the field for writing the message. It improves the readability.
"it dosen't calculate properly" - I cannot know, what this means. Of couse the min() function determines the minimal element. Then what does "not properly" mean? If the results differ from your expectations, it is required to mention, what you expect and what you get.
(c*1) ? You multiply several times by 1, but this is a waste of time for the computations and for typing also.
I cannot run your code due to the lack of input values.
Please remember that it is hard to understand a sentence like this: "After calculate Ets and OEts I want to calculate minimum fitness and minimum Ofitness value then union of them get the union i have to sort them and select 10 minimum value." I have almost no chance to know, what this means.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Performance and Memory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!