# split a 2d matrix and create new 3d matrix from the results of the 2d matrix

14 ビュー (過去 30 日間)
Aleksandra Ksiezyk 2020 年 5 月 5 日
hej !
i have a matrix T_A (size 12x11). i would like to split this matrix the way, i will get 3d matrix of the size (24x11x12). the way i want to do it is to take each raw from the T_A matrix and multiply it by a size i want to get that is: T_A(i,:).* ones(24,11) so as a result i will get a matrix with 11 "vertically-same" values (i pasted my code below, but i am doing sth wrond and i am getting an error). then i should get 12 individual matrixes and connect them as a one 3d matrix, but i am strugling how to do it. any help would be grateful... thank you in advance !
T_A = [1.9563 1.8572 1.7581 1.6590 1.5600 1.4609 1.3618 1.2627 1.1636 1.0645 0.9654
-1.1154 -0.8590 -0.6027 -0.3463 -0.0900 0.1664 0.4228 0.6791 0.9355 1.1918 1.4482
6.0627 6.1125 6.1623 6.2121 6.2620 6.3118 6.3616 6.4114 6.4612 6.5111 6.5609
7.6072 7.8747 8.1422 8.4097 8.6772 8.9448 9.2123 9.4798 9.7473 10.0149 10.2824
15.6328 15.6707 15.7085 15.7463 15.7841 15.8219 15.8597 15.8975 15.9353 15.9731 16.0109
16.8050 16.9733 17.1416 17.3100 17.4783 17.6466 17.8150 17.9833 18.1516 18.3200 18.4883
21.8550 21.8060 21.7570 21.7080 21.6590 21.6100 21.5610 21.5120 21.4630 21.4140 21.3650
20.3360 20.3509 20.3658 20.3808 20.3957 20.4106 20.4256 20.4405 20.4554 20.4704 20.4853
20.7990 20.5477 20.2964 20.0452 19.7939 19.5427 19.2914 19.0401 18.7889 18.5376 18.2863
13.2610 13.1530 13.0449 12.9368 12.8288 12.7207 12.6126 12.5045 12.3965 12.2884 12.1803
9.9109 9.6608 9.4108 9.1607 8.9107 8.6606 8.4105 8.1605 7.9104 7.6604 7.4103
2.4091 2.3945 2.3799 2.3653 2.3507 2.3361 2.3215 2.3068 2.2922 2.2776 2.2630 ]
for i = 1:11
Matrix_T_A(24,i) = T_A(i,:).* ones(24,11)
end

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

### 採用された回答

Tommy 2020 年 5 月 5 日
I believe this should do what you want:
Matrix_T_A = permute(repmat(T_A, 1, 1, 24), [3 2 1]);
Using the for loop, T_A(i,:).* ones(24,11) is a 24x11 matrix, so it needs a 24x11 space within Matrix_T_A for storage:
Matrix_T_A2 = ones(24,11,12);
for i = 1:12
Matrix_T_A2(:,:,i) = T_A(i,:).* ones(24,11);
end
>> isequal(Matrix_T_A, Matrix_T_A2)
ans =
logical
1
##### 1 件のコメント表示非表示 なし
Aleksandra Ksiezyk 2020 年 5 月 5 日
works perfectly !!! thx a lot !!!!

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

### その他の回答 (1 件)

TADA 2020 年 5 月 5 日
If I got it right
Matrix_T_A = repmat(reshape(T_A', 1, size(x, 2), size(x,1)), 24, 1, 1)
##### 1 件のコメント表示非表示 なし
Aleksandra Ksiezyk 2020 年 5 月 5 日
i am getting an error, but the answer above is correct, thank you !!

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

### Community Treasure Hunt

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

Start Hunting!

Translated by