reshaping cell containing double arrays

1 Ansicht (letzte 30 Tage)
MiauMiau
MiauMiau am 10 Okt. 2017
Bearbeitet: Guillaume am 10 Okt. 2017
Hi,
I have (as an example) the following cell array:
test =
1×4 cell array
[40×1 double] [40×1 double] [40×1 double] [40×1 double]
I want test to be a 1 x 1 cell, containing the double arrays (from left to right) as one double array of dimension 160 x 1. reshape(test,[160,1]) does not work directly here. What can I do?

Antworten (3)

KSSV
KSSV am 10 Okt. 2017
Bearbeitet: KSSV am 10 Okt. 2017
test = cell(1,4) ;
for i = 1:4
test{i} = rand(40,1) ;
end
iwant = cell2mat(test) ;
iwant = {iwant(:)} ;
  2 Kommentare
MiauMiau
MiauMiau am 10 Okt. 2017
Is there no quicker way than looping?
Guillaume
Guillaume am 10 Okt. 2017
The loop is only to build the demo data.

Melden Sie sich an, um zu kommentieren.


Guillaume
Guillaume am 10 Okt. 2017
That's because what you want is not reshaping but a concatenation. (The matrices may not be contiguous in memory):
test = [test{:}]
  2 Kommentare
MiauMiau
MiauMiau am 10 Okt. 2017
That is giving me a 40x4 matrix...?!
Guillaume
Guillaume am 10 Okt. 2017
Bearbeitet: Guillaume am 10 Okt. 2017
Oh yes, your vectors are column vectors. Concatenate them vertically then:
test = vertcat(test{:})

Melden Sie sich an, um zu kommentieren.


KL
KL am 10 Okt. 2017
Bearbeitet: KL am 10 Okt. 2017
test = cell2mat(test');
this?

Kategorien

Mehr zu Matrices and Arrays 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!

Translated by