Looping with arrays of two different lengths

1 回表示 (過去 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];
end
for i = 1:2*n
for j = 1:2*n
if i ~=j && i ~= n+j
A = [A; i, j];
end
end
end
for i = n+1:2*n
A = [A; i, 2*n+1];
end
t = randi(15, length(A)-1, 1);
t=[0;t]
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);

回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by