Looping with arrays of two different lengths

조회 수: 3(최근 30일)
Anurag Gupta
Anurag Gupta 2020년 10월 12일
편집: Anurag Gupta 2020년 10월 12일
My code is written as follows, Now here as we can see that a matrix A is generated of size 34x2 double which shows combination of travel between nodes(represented by n). t shows travel times between these nodes, therefore t also has 34 rows and its size is 34x1 double. now e and l correspond to number of nodes(n) therefor their size is 8x1 each respectively. I want to use the formula: e+t> l in one/many loops and want to make that index of A=[0;0] wherein this forua is true. in this formula t represents travel times between nodes and e and l are variable assosciated with n. the code is below for better understanding.
T_up = 1000;
n = 3;
A = [];
A = [A; 0, 2*n+1];
for i = 1:n
A = [A; 0, i];
for i = 1:2*n
for j = 1:2*n
if i ~=j && i ~= n+j
A = [A; i, j];
for i = n+1:2*n
A = [A; i, 2*n+1];
t = randi(15, length(A)-1, 1);
e = randi(150, n, 1);
l = [T_up; e + max(t(:)); e + 2*max(t(:)) + 25; T_up];
dlmwrite('l.txt', l);
e = [0; e; e; 0];
dlmwrite('e.txt', e);



Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by