add columns to matrix

6 次查看(过去 30 天)
A=(1 2 3 4)
A = 1×4
1 2 3 4
B=(2 4 5 6 8 9 4 1)
B = 1×8
2 4 5 6 8 9 4 1
C=[A,B]
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
C=1 0
2 0
3 0
4 0
0 2
0 4
0 5
0 6
0 8
0 9
0 4
0 1
like this i would like to generate matrix .Please help me in this how to write a program .
I need to add like this six files as shown above upto size 1084x6 matrix.

采纳的回答

Steven Lord
Steven Lord 2022-8-7
In general you can use blkdiag.
A=[1 2 3 6 ];
B=[4 5 5 6 9 8 7 6 9 6 8 6 9];
D=[4 1 2 3 5 68 9 6 9 6 9 6 9 6 9 63 45 82 85 96 74 52 63 10 30 23 65 6 66 33 66 ];
E=[5 4 6 5 4 8 9 6 9 6 8 6];
F=[4 8 9 7 8 6 9 6 8 2 21 3 6 56 36];
G=[7 8 9 9 6 8 6 45 25 33 66 33 14 25 36 36 12];
result = blkdiag(A, B, D, E, F, G).'
result = 92×6
1 0 0 0 0 0 2 0 0 0 0 0 3 0 0 0 0 0 6 0 0 0 0 0 0 4 0 0 0 0 0 5 0 0 0 0 0 5 0 0 0 0 0 6 0 0 0 0 0 9 0 0 0 0 0 8 0 0 0 0
  1 个评论
solleti prabhakarchary
thank you. It will work for text files also
A=load(a.txt); in this manner

请先登录,再进行评论。

更多回答(1 个)

solleti prabhakarchary
编辑:solleti prabhakarchary 2022-8-7
A=[1 2 3 6 ];
B=[4 5 5 6 9 8 7 6 9 6 8 6 9];
D=[4 1 2 3 5 68 9 6 9 6 9 6 9 6 9 63 45 82 85 96 74 52 63 10 30 23 65 6 66 33 66 ];
E=[5 4 6 5 4 8 9 6 9 6 8 6];
F=[4 8 9 7 8 6 9 6 8 2 21 3 6 56 36];
G=[7 8 9 9 6 8 6 45 25 33 66 33 14 25 36 36 12];
A1=[A;zeros(size(A))]';
B1=[zeros(size(B));B]';
D1=[zeros(size(D));D]';
E1=[zeros(size(E));E]';
F1=[zeros(size(F));F]';
G1=[zeros(size(G));G]';
C=[A1;B1;D1;E1;F1;G1]
C = 92×2
1 0 2 0 3 0 6 0 0 4 0 5 0 5 0 6 0 9 0 8
i would like to get in nx6 columns .
1 0 0 0 0 0
2 0 0 0 0 0
3 0 0 0 0 0
6 0 0 0 0 0
0 4 0 0 0 0
0 5 0 0 0 0
0 5 0 0 0 0
0 6 0 0 0 0
0 9 0 0 0 0
0 8 0 0 0 0
0 7 0 0 0 0
0 6 0 0 0 0
0 9 0 0 0 0
0 6 0 0 0 0
0 8 0 0 0 0
0 6 0 0 0 0
0 9 0 0 0 0
0 0 4 0 0 0
0 0 1
0 2
0 3
0 5
0 68
0 9
0 6
0 9
6
9
6
9
6
9
63
45
82
85
96
74
52
63
10
30
23
65
6
66
33
66
In this way need to get how to write program .Please help me in this. Thank you.

类别

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