Creating a new matrix based on the data from other two matrices
1 回表示 (過去 30 日間)
古いコメントを表示
I have two matrices:
g1=[0.3 0.3 0.4 0.4 0.5 0.5 ...;
0.1 0.2 0.1 0.2 0.1 0.2 ...];
g2=[0.3 0.3 0.3 0.4 0.4 0.4 0.5 0.5 0.5 ...;
0.3 0.4 0.5 0.3 0.4 0.5 0.3 0.4 0.5];
Matrix g1 is 2 x (2*nx) dimension, and matrix g2 is 2 x (3*nx) - where nx depends from one of the previous steps.
Now, I want to make a new matrix which will take first two rows of matrix g1, then first three rows of matrix g2, then again two rows of matrix g1, three rows of matrix g2 and so on up to the end.
So the final matrix should looks:
g=[0.3 0.3 0.3 0.3 0.3 0.4 0.4 0.4 0.4 0.4 0.5 0.5 0.5 0.5 0.5 ...;
0.1 0.2 0.3 0.4 0.5 0.1 0.2 0.3 0.4 0.5 0.1 0.2 0.3 0.4 0.5 ...];
clc;clear;close all;
nx=3; % for example (it should be calculated)
g_1=[0.3 0.3 0.4 0.4 0.5 0.5;
0.1 0.2 0.1 0.2 0.1 0.2];
g_2=[0.3 0.3 0.3 0.4 0.4 0.4 0.5 0.5 0.5;
0.3 0.4 0.5 0.3 0.4 0.5 0.3 0.4 0.5];
for i=1:nx
g=[g_1(:,1+(i-1)*2:i*2) g_2(:,1+(i-1)*3:i*3)]
i=i+1
end
g
In this way, I get only last five terms for A:
g =
0.5000 0.5000 0.5000 0.5000 0.5000
0.1000 0.2000 0.3000 0.4000 0.5000
I know in the definition of matrix g, it should be something like g(i), but I don't know how to do it. Any help would be appreciated.
Thanks in advance.
0 件のコメント
採用された回答
Andrei Bobrov
2019 年 12 月 23 日
out = reshape([reshape(g1',2,[],2);reshape(g2',3,[],2)],[],2)'
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!