doubt in for Loop

Hi,
Now i want to execute a formula;
if e+t<L
.......(some logic)
wherein the size of e= 8x1 doubt
t=28x1 doubt
L=8x1 doubt.
Is there anyway I can execute this line.
Please help.

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 10 月 8 日

0 投票

for K = 1 : numel(e)
if all(e(K) + t < L)
.......(some logic)
end
end

4 件のコメント

Anurag Gupta
Anurag Gupta 2020 年 10 月 9 日
Hi Sir,
it shows error Matrix dimension must agree.
is it because dimensions of all variables are different?
thanks and regards.
Walter Roberson
Walter Roberson 2020 年 10 月 9 日
for K = 1 : numel(t)
if all(e + t(K) < L)
.......(some logic)
end
end
Anurag Gupta
Anurag Gupta 2020 年 10 月 9 日
Hi Sir,
I am getting this error 'Index exceeds the number of array elements (8).' as e is a matrix with 8 elements and whenever the value of K reaches 9 it shows 'Index exceeds the number of array elements (8).' error.
Sir I will try to explain my entire problem in brief and it would be great if you can spare time to read it and provide me with a solution.
so now, I have a Matrix A of size 34x2 double,of which each row represents a arc. depending on this I have value of t 34x1 double, of which each row represents time taken to travel in each arc. now I have a constraint such that e and l can be of size 8x1 double.
now I want to remove few arcs from A such that: (e+t<l) now since t and e are of different sizes it is proving to be difficult to work them out under one for loop. it would be great if you can help.
Regards,
Anurag Gupta
Walter Roberson
Walter Roberson 2020 年 10 月 9 日
The code I posted,
for K = 1 : numel(t)
if all(e + t(K) < L)
.......(some logic)
end
end
does not index e, so you will not get an error about the number of elements in e.

この質問は閉じられています。

製品

リリース

R2019b

質問済み:

2020 年 10 月 8 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by