vertical or horizontal array random combination in single array
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Bruno Luong
on 15 Jun 2022
Edited: Bruno Luong
on 15 Jun 2022
A={[12;13] ;[1,5] ;[5;6;7]; [1,3,5,4]};
B = cellfun(@(x) x(:), A, 'unif', 0);
C = cat(1,B{:})
0 Comments
More Answers (1)
Voss
on 15 Jun 2022
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 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!