vertical or horizontal array random combination in single array
2 次查看(过去 30 天)
显示 更早的评论
Hi all
As the title above, suppose i have matrix A like:
A={[12;13] ;[1,5] ;[5;6;7]; [1,3,5,4]};
i want the matrix A have vertical or horizontal array, look like:
A = 12 13 1 5 5 6 7 1 3 5 4
or
A =
12
13
1
5
5
6
7
1
3
5
4
i know for produce horizontal array using:
[[12;13]' [1,5] [5;6;7]' [1,3,5,4]]
and for vertical array using:
[[12;13] ;[1,5]' ;[5;6;7]; [1,3,5,4]']
but note for this situation i work with big and long array, where has the number ; and , various.
I really appreciate the help. tks
0 个评论
采纳的回答
Bruno Luong
2022-6-15
编辑:Bruno Luong
2022-6-15
A={[12;13] ;[1,5] ;[5;6;7]; [1,3,5,4]};
B = cellfun(@(x) x(:), A, 'unif', 0);
C = cat(1,B{:})
0 个评论
更多回答(1 个)
Voss
2022-6-15
A={[12;13] ;[1,5] ;[5;6;7]; [1,3,5,4]};
% make each element of A a row vector
A = cellfun(@(x)x(:).',A,'UniformOutput',false)
% horizontally concatenate all elements of A
A = [A{:}]
% or ...
A={[12;13] ;[1,5] ;[5;6;7]; [1,3,5,4]};
% make each element of A a column vector
A = cellfun(@(x)x(:),A,'UniformOutput',false)
% vertically concatenate all elements of A
A = vertcat(A{:})
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!