Generate all possible combinations of input vector Then store the input and outputs in each iteration in .mat file
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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)));
0 comentarios
Respuesta aceptada
Matt J
el 4 de Mzo. de 2022
Editada: Matt J
el 4 de Mzo. de 2022
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)
6 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!