using 2 variables in one for loop

2 ビュー (過去 30 日間)
sajawal feroze
sajawal feroze 2019 年 11 月 5 日
回答済み: Chidvi Modala 2019 年 12 月 20 日
for i=5:8,a=1:4
for j=5:8,b=1:4
K(lm(i),lm(j))=Kg2(a,b);
end
end
Ks=Ks+K;
K=zeros(14);
How can I use this loop? As it is just picking values for i=1 and j=1 and not completing the loop.
  1 件のコメント
Muhammad Usman
Muhammad Usman 2019 年 11 月 5 日
What you actually want to do?
Totally confusing

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

回答 (1 件)

Chidvi Modala
Chidvi Modala 2019 年 12 月 20 日
for loop executes a group of statements in a loop for a specified number of times with a single index. In my understanding, you are trying to use 2 indexes. So a=1:4 and b=1:4 are being executed as statements. You can use the below code for your requirement
I=5:8;
A=1:4;
J =5:8;
B=1:4;
for p=1:numel(I)
i=I(p);
a=A(p);
for q=1:numel(J)
j=J(q);
b=B(q);
K(lm(i),lm(j))=Kg2(a,b);
end
end

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by