reshaping cell containing double arrays

1 回表示 (過去 30 日間)
MiauMiau
MiauMiau 2017 年 10 月 10 日
編集済み: Guillaume 2017 年 10 月 10 日
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?

回答 (3 件)

KSSV
KSSV 2017 年 10 月 10 日
編集済み: KSSV 2017 年 10 月 10 日
test = cell(1,4) ;
for i = 1:4
test{i} = rand(40,1) ;
end
iwant = cell2mat(test) ;
iwant = {iwant(:)} ;
  2 件のコメント
MiauMiau
MiauMiau 2017 年 10 月 10 日
Is there no quicker way than looping?
Guillaume
Guillaume 2017 年 10 月 10 日
The loop is only to build the demo data.

サインインしてコメントする。


Guillaume
Guillaume 2017 年 10 月 10 日
That's because what you want is not reshaping but a concatenation. (The matrices may not be contiguous in memory):
test = [test{:}]
  2 件のコメント
MiauMiau
MiauMiau 2017 年 10 月 10 日
That is giving me a 40x4 matrix...?!
Guillaume
Guillaume 2017 年 10 月 10 日
編集済み: Guillaume 2017 年 10 月 10 日
Oh yes, your vectors are column vectors. Concatenate them vertically then:
test = vertcat(test{:})

サインインしてコメントする。


KL
KL 2017 年 10 月 10 日
編集済み: KL 2017 年 10 月 10 日
test = cell2mat(test');
this?

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by