for loop index picking only elements of given vector

1 回表示 (過去 30 日間)
Dharma Khatiwada
Dharma Khatiwada 2022 年 8 月 7 日
コメント済み: Voss 2022 年 8 月 17 日
Hi all,
I am trying to see the loop index j only picking the element of given vector V.
for example for index j can pick value 1, 4, 8, 11 and so on.
Expecting your help.
Thanks
Dharma
syms x t
c(1)=10*dirac(x-1);
V=[1 4 8 11 15 18 22];
for j= .....%it needs to pick only elements of above vector V
c(x)=c(x)+dirac(x-j);
end

採用された回答

Voss
Voss 2022 年 8 月 7 日
  2 件のコメント
Dharma Khatiwada
Dharma Khatiwada 2022 年 8 月 14 日
Hi I have a quick question. How do I start with second value of j (j=4) in the for loop?
Thank you
syms x t
c2(x)= 5*dirac(x-1);% This is first value for j=1 (first Monday of iteration)
n_weeks = 60;
vec = reshape((0:n_weeks-1)*7+[1;4],1,[]);
for j=vec% It is also counting first value. How do avoid first value?
%I want to start with second value of vec which is 4
c2(x) = c2(x)+5*dirac(x-j);
end
Voss
Voss 2022 年 8 月 17 日
for j=vec(2:end)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by