필터 지우기
필터 지우기

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by