How to obtain a matrix from the iterations of a for loop?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I woud like to obtain a matrix C[84x24] with every row filled, by the moltiplication between each row af a Matrix A[7x24] by each element of vector B[1x12].
I am able to do it only by this loop with "cell command at the end but i'm looking for an easyer way .
A=[ 0.2167 0.2467 0.2520 0.2652 0.2661 0.2907 0.3498 0.4211 0.5348 0.5735 0.5242 0.4361 0.4810 0.5233 0.5365 0.5356 0.5533 0.7629 0.8317 0.8704 0.7770 0.7321 0.6563 0.5427
0.2406 0.2738 0.2797 0.2944 0.2954 0.3227 0.3883 0.4675 0.5936 0.6367 0.5819 0.4841 0.5340 0.5809 0.5956 0.5946 0.6142 0.8469 0.9232 0.9663 0.8626 0.8127 0.7286 0.6024
0.2440 0.2778 0.2837 0.2986 0.2996 0.3274 0.3938 0.4742 0.6021 0.6458 0.5902 0.4910 0.5416 0.5892 0.6041 0.6031 0.6230 0.8591 0.9364 0.9801 0.8749 0.8244 0.7390 0.6111
0.2453 0.2792 0.2851 0.3001 0.3011 0.3290 0.3958 0.4766 0.6052 0.6490 0.5932 0.4935 0.5444 0.5922 0.6072 0.6062 0.6261 0.8634 0.9412 0.9850 0.8794 0.8285 0.7428 0.6142
0.2453 0.2792 0.2851 0.3001 0.3011 0.3290 0.3958 0.4766 0.6052 0.6490 0.5932 0.4935 0.5444 0.5922 0.6072 0.6062 0.6261 0.8634 0.9412 0.9850 0.8794 0.8285 0.7428 0.6142
0.2448 0.2786 0.2846 0.2995 0.3005 0.3284 0.3950 0.4756 0.6040 0.6477 0.5920 0.4925 0.5433 0.5910 0.6060 0.6050 0.6249 0.8617 0.9393 0.9831 0.8776 0.8268 0.7413 0.6129
0.2369 0.2696 0.2754 0.2899 0.2908 0.3178 0.3823 0.4603 0.5845 0.6269 0.5730 0.4767 0.5258 0.5720 0.5865 0.5855 0.6048 0.8340 0.9091 0.9514 0.8494 0.8003 0.7174 0.5932];
B=[0.999; 0.992; 0.939; 0.850; 0.810; 0.803; 0.796; 0.792; 0.821; 0.929; 0.990; 1.000];
for j=1:12;
C=A*B(j);
cell_C{j}=C;
end
D=[cell_C{1,1};cell_C{1,2};cell_C{1,3};cell_C{1,4};cell_C{1,5};cell_C{1,6};cell_C{1,7};cell_C{1,8};cell_C{1,9};cell_C{1,10};cell_C{1,11};cell_C{1,12}];
D
0 Commenti
Risposta accettata
Voss
il 21 Giu 2022
Modificato: Voss
il 21 Giu 2022
A=[ 0.2167 0.2467 0.2520 0.2652 0.2661 0.2907 0.3498 0.4211 0.5348 0.5735 0.5242 0.4361 0.4810 0.5233 0.5365 0.5356 0.5533 0.7629 0.8317 0.8704 0.7770 0.7321 0.6563 0.5427
0.2406 0.2738 0.2797 0.2944 0.2954 0.3227 0.3883 0.4675 0.5936 0.6367 0.5819 0.4841 0.5340 0.5809 0.5956 0.5946 0.6142 0.8469 0.9232 0.9663 0.8626 0.8127 0.7286 0.6024
0.2440 0.2778 0.2837 0.2986 0.2996 0.3274 0.3938 0.4742 0.6021 0.6458 0.5902 0.4910 0.5416 0.5892 0.6041 0.6031 0.6230 0.8591 0.9364 0.9801 0.8749 0.8244 0.7390 0.6111
0.2453 0.2792 0.2851 0.3001 0.3011 0.3290 0.3958 0.4766 0.6052 0.6490 0.5932 0.4935 0.5444 0.5922 0.6072 0.6062 0.6261 0.8634 0.9412 0.9850 0.8794 0.8285 0.7428 0.6142
0.2453 0.2792 0.2851 0.3001 0.3011 0.3290 0.3958 0.4766 0.6052 0.6490 0.5932 0.4935 0.5444 0.5922 0.6072 0.6062 0.6261 0.8634 0.9412 0.9850 0.8794 0.8285 0.7428 0.6142
0.2448 0.2786 0.2846 0.2995 0.3005 0.3284 0.3950 0.4756 0.6040 0.6477 0.5920 0.4925 0.5433 0.5910 0.6060 0.6050 0.6249 0.8617 0.9393 0.9831 0.8776 0.8268 0.7413 0.6129
0.2369 0.2696 0.2754 0.2899 0.2908 0.3178 0.3823 0.4603 0.5845 0.6269 0.5730 0.4767 0.5258 0.5720 0.5865 0.5855 0.6048 0.8340 0.9091 0.9514 0.8494 0.8003 0.7174 0.5932];
B=[0.999; 0.992; 0.939; 0.850; 0.810; 0.803; 0.796; 0.792; 0.821; 0.929; 0.990; 1.000];
kron method:
D_test = kron(B,A)
Compare to the cell array method:
for j=1:12;
C=A*B(j);
cell_C{j}=C;
end
D=vertcat(cell_C{:});
The result is the same:
isequal(D_test,D)
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!