How can I convert cell array to an arrary matrix?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Abdullah Türk
am 7 Jan. 2024
Bearbeitet: Stephen23
am 9 Jan. 2024
Hi,
I have a cell array and I want to ceovert it to an array matrix.
Can I convert this cell array as follows:
array_matrix = [6 11 20 12 15 19 12 4 18 16 3 13 1 14 7 8 5 10 9 17]
Is there a way to do this?
My cell matrix is attached.
1 Kommentar
Akzeptierte Antwort
Dyuman Joshi
am 7 Jan. 2024
Verschoben: Dyuman Joshi
am 7 Jan. 2024
in = load('cell_array.mat')
x = in.ans;
out = vertcat(x{:}).'
3 Kommentare
Weitere Antworten (2)
Sulaymon Eshkabilov
am 7 Jan. 2024
This is how it can be attained:
A = load('cell_array.mat').ans;
for ii = 1:numel(A)
H = A{ii};
K{ii} = cat(1, H(:)');
end
array_matrix = (horzcat(K{:}))
3 Kommentare
Voss
am 7 Jan. 2024
Bearbeitet: Voss
am 7 Jan. 2024
@Abdullah Türk: If you know that all the cells of your cell array contain column vectors of the same class (as is the case in the variable ans in the posted mat file), then @Dyuman Joshi's approach will work:
x = load('cell_array.mat').ans;
out = vertcat(x{:}).'
Alternatively, if the cells can contain arrays of any shape and dimensionality (still of the same class), then you'll need to reshape them before doing the vertical concatenation (vertcat). For example:
x = load('cell_array.mat').ans;
x_col = cellfun(@(m)reshape(m,[],1),x,'UniformOutput',false);
out = vertcat(x_col{:}).'
1 Kommentar
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!