2-for loop iteration to output a matrix

4 ビュー (過去 30 日間)
Cutie
Cutie 2022 年 2 月 14 日
コメント済み: Cutie 2022 年 2 月 14 日
I want to use for-loop for my entire code for simulation.
Specifically, i want to output results of each iteration with 2 for-loops in a matrix. I use the example code to explain my problem
A=[5 10 15 45] %changing variables in the code
B=[2 4] %another changing variable for iteration
D=[] %final output matrix. I want it to be 2 by 4 (such that output of condition B(1,1) & A(:) makes row1 in D...
for i=1:size(A,2)
w=A(i)
for j=1:size(B,2)
p=B(j)
num=4
mix=2
[ar, A_d, pha, ata] = GmmClas(B, num, mix) %GmmClas
C= gamu(ar, A_d, pha, A) %gamu is a function
D=[D C] %but I want this output in matrix 92 by4)not as vector
end
end
The entire code is working. I only want to create the for-loop for simulation purpose as it will be tediuos manually changing the varying parameters after each iteration.
D is to be the final output (size -2 by 4) where row1 will be output of when B=2 and A=[5 10 15 45] and row 2 will be B=4 and A=[5 10 15 45]

採用された回答

Matt J
Matt J 2022 年 2 月 14 日
編集済み: Matt J 2022 年 2 月 14 日
A=[5 10 15 45]; %changing variables in the code
B=[2 4]; %another changing variable for iteration
D=A+B'
D = 2×4
7 12 17 47 9 14 19 49
  5 件のコメント
Matt J
Matt J 2022 年 2 月 14 日
編集済み: Matt J 2022 年 2 月 14 日
A=[5 10 15 45] %changing variables in the code
B=[2 4] %another changing variable for iteration
Na=numel(A); Nb=numel(B);
D=nan(Nb,Na); %final output matrix. I want it to be 2 by 4 (such that output of condition B(1,1) & A(:) makes row1 in D...
for i=1:Na
w=A(i);
for j=1:Nb
p=B(j);
num=4;
mix=2;
[ar, A_d, pha, ata] = GmmClas(B, num, mix); %GmmClas
D(j,i)= gamu(ar, A_d, pha, A); %gamu is a function
end
end
Cutie
Cutie 2022 年 2 月 14 日
Thank you @Matt J. The above works perfectly. I appreciate.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by