Indexed exceeds matrix dimensions

조회 수: 1 (최근 30일)
Sushree Patra
Sushree Patra 2018년 12월 5일
댓글: Walter Roberson 2020년 5월 27일
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');
% placed 13 node according to the co-ordinates
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 the output node
plot(A,B, 'mo-', 'MarkerSize', 10,'LineWidth', 2);
hold on
% placed 50 point randomly
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
disp (distances);
dist1 = sqrt((x2-A).^2+(y2-B).^2)
%disp (dist1);
dist2 =sqrt((x1-A).^2+(y1-B).^2)
%disp (dist2);
% Find min distance
disp (minDistance);
a=1:50;
%choose 10 node randomly from 50 node
out=a(randperm(numel1(a),10))
s=250;
Et=16.7;
Eamp=1.97;
%caculate the energy consumption of 13 sensor to that choosen 10 random node which store in out
%?_? (?, ?_?? )=?(?t+ ???? ???^2)
for i=1:10
for k=1:13
Ets(i,k)=s*(Et+Eamp*(distances(k,out(i)).^2));
end
end
disp(Ets);
N=10;
data_agg=1;
Er=36.1;
%calculate the energy consumption of 10 relay node while transmiitting to 1 output device
%?_??=???? (?, ???/d??? ) )+????t
%?_??=(?−1) ?r(?)
%?_? (?)= ?r(?)
for i=1:10
for k= 1:1
Etf(i,k)= N*data_agg*Et*(s*dist1(k,out(i)))+N*s*data_agg*Et; %transmission energy of relay node
Erf=(N-1)*Er*s;%reception energy of relay node
Ef_total(i,k)=Etf(i,k)+Erf %total energy consumption of relay
end
end
d0=40;
c=10;
%find out fitness function of that 10 relay node eith respect to 13 sensor node
%Fitness =c*∑j∈R*cost(j)*xj +c*(∑i∈S,j∈R Ei * xij+∑j∈R xj*Er)+ c* √(∑i∈S,j∈R(dij-d0)^2 ))/(∑i∈S,j∈R xij)+c*(∑i∈S,j∈R xij )/(⋃i∈S,j∈R xij)
% xj=1,if relay exist otherwise 0
%S=13 sensor
%R=10 relay stored in out
for i=1:10
for k=1:13
fitness(i,k)= (c*out(i)*1)+(c*(Ets(k,out(i))*1+Ef_total(k,out(i))*1))+(c*sqrt((distances(k,out(i))-d0).^2))+c;
end
end
disp(fitness)
  댓글 수: 3
Sushree Patra
Sushree Patra 2018년 12월 5일
distance is defined and this one is the part of code my problem is when i calculate the fitness function then it shows indexed exceeds matrxmatrix dimensions
Sushree Patra
Sushree Patra 2018년 12월 5일
due to shortage of space i put end in same line. please help me out.
if the code is not clear then i will send the total code

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 12월 5일
Ets is 10 by 13.
Your fitness calculation includes Ets(k,out(i)) . But out(i) can be up to 50 and k can be up to 13 . You probably want Ets(i,k)
  댓글 수: 6
RAJENDRA KUMAR SHARMA
RAJENDRA KUMAR SHARMA 2020년 5월 27일
편집: Walter Roberson 2020년 5월 27일
how to make objective function of coordination relay please anybody explain
Walter Roberson
Walter Roberson 2020년 5월 27일

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Luna
Luna 2018년 12월 5일
편집: Luna 2018년 12월 5일
Your out and Ets variable is below:
out = [21 20 24 26 39 36 1 28 33 15] % 1x10 array
Ets = [.. ..] % 10x13 matrix
Ef_total = [.. ..] % 10x1 array
When you get in for loop for k = 1:10 and i =1:13, out(i) return to you the first, second, third element of the out array.
For example i = 1. out(i) will be 21. Your Ets only have 10 rows and 13 columns. You can't get the 21st column element you are asking for in bolded below. Because there is only 13 columns. Same for Ef_total.
(Ets(k,out(i)) will be Ets(k,21) ... etc.. % you get the idea)
The below formula in for loop definetely cause error.
fitness(i,k)= (c*out(i)*1)+(c*(Ets(k,out(i))*1+Ef_total(k,out(i))*1))+(c*sqrt((distances(k,out(i))-d0).^2))+c;
You should change them as follows but check if it does the correct calculation:
fitness(i,k)= (c*out(i)*1)+(c*(Ets(i,k)*1+Ef_total(i,1)))+(c*sqrt((distances(k,out(i))-d0).^2))+c;
  댓글 수: 5
Luna
Luna 2018년 12월 5일
Did it fix your code?
Sushree Patra
Sushree Patra 2018년 12월 5일
yes it fixed in my code Screenshot_2018-12-05-20-23-42-008_com.android.chrome.png

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Design of Experiments (DOE)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by