dividing a matrix into equal submatrices

1 回表示 (過去 30 日間)
Matt
Matt 2012 年 5 月 3 日
Hello all,
I need to take a matrix that is one column of non integers and divide it into 10 equal length matrices that are 1/10 of the original, but still one column, for analysis. mat2cell doesn't work on non integers and nothing I have been searching in has given an answer. I'm fairly new to MATLAB, so please be kind if this is a fairly simple request. Any help would be awesome.
Thanks, Matt

採用された回答

Kye Taylor
Kye Taylor 2012 年 5 月 3 日
I assume that your vector, x, is n-by-1 where n is divisible by 10.
Try
xIntoTenPieces = reshape(x,[],10);
which produces a matrix, each column is is 1/10 of the original vector x. You can access the kth column with the syntax
xIntoTenPieces(:,k)
  2 件のコメント
Matt
Matt 2012 年 5 月 3 日
Exactly what I wanted to do. Thanks so much!
Kye Taylor
Kye Taylor 2012 年 5 月 3 日
My pleasure!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 5 月 3 日
mat2cell() works fine for any numeric array.
L = size(x,1);
L10 = L / 10;
mat2cell(x, repmat(L10,1,10), 1)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by