フィルターのクリア

Generate all possible combinations of input vector Then store the input and outputs in each iteration in .mat file

1 回表示 (過去 30 日間)
In the following code I want to generate all probability of being 0.5 in vector 'Pd' .
For example:
In the first iteration Pd will be as the following : Pd=[0.5 1 1 1 1 1 1]'
In the second iteration Pd will be as the following : Pd=[1 0.5 1 1 1 1 1]'
.
.
.
In i number of iteration Pd will be as the following : Pd=[1 0.5 0.5 0.5 1 1 1]'
In i number of iteration Pd will be as the following : Pd=[0.5 0.5 0.5 0.5 0.5 0.5 0.5]'
And so on ... (I want all possible combinations)
Then I want to store 'Pd' vector , 'Dd' matrix and 'w' vector in file which is named 'Comb#number of itertaion' (i.e , Comb1 , Comb2 ... ) in each iteration.
This is a part from the code:
Ph=[1 1 1 1 1 1 1]' ;
Pd=[0.5 1 1 1 1 1 1]' ;
Kd=zeros(14) ; Kh=zeros(14) ;
for i=1:7 ;
Ki=build_beam(i) ;
Kd=Kd+Pd(i)*Ki ;
Kh=Kh+Ph(i)*Ki ;
end ;
a=1:2:14;
r=7 ;
[Vd,Dd]=eig(Kd,M) ;
Dd=diag(Dd) ;
[Dd,I]=sort(Dd) ; Dd=Dd(1:vibmodes) ;
Vd=Vd(:,I); Td=Vd(:,1:vibmodes) ; Td=Td(a,:) ;
Dd=diag(Dd) ;
w=sqrt((diag(Dh)));

採用された回答

Matt J
Matt J 2022 年 3 月 4 日
編集済み: Matt J 2022 年 3 月 4 日
Well, here are all the combinations. You can loop through the rows of Pd and save them after whatever processing you wish. You've seen examples of similar things in previous posts. However, I think it's probably a bad idea to store the results to separate .mat files. You should probably store them all in one matfile as arrays.
[Pd{1:7}]=ndgrid([0.5,1]);
Pd=reshape( cat(8,Pd{:}) ,[],7)
Pd = 128×7
0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 1.0000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 1.0000 0.5000 0.5000 0.5000 0.5000 0.5000 1.0000 1.0000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 1.0000 0.5000 0.5000 0.5000 0.5000 1.0000 0.5000 1.0000 0.5000 0.5000 0.5000 0.5000 0.5000 1.0000 1.0000 0.5000 0.5000 0.5000 0.5000 1.0000 1.0000 1.0000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 1.0000 0.5000 0.5000 0.5000 1.0000 0.5000 0.5000 1.0000 0.5000 0.5000 0.5000
  6 件のコメント
M
M 2022 年 3 月 4 日
@Matt J Thank you so much, it is working now.

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

その他の回答 (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