shuffling elements between two matrices

Hi all,
I have two signals meg1 and meg2: [3 x 1801 x 53] and [3 x 1801 x 60] type meeg. I can easily split them into three arrays of : 1 x 1801 x 53 type double. But what I need to do is to make both meg signals as random as possible so preferebly shuffle the elements between them two like n times. I tried to do it just within each matrix with function randswap http://www.mathworks.co.uk/matlabcentral/fileexchange/12621-randswap but it gives an error for elements type double. Has anyone got any idea how to do it? Would be veeeery grateful!!
Many thanks in advance, Lidia

 採用された回答

Image Analyst
Image Analyst 2014 年 7 月 6 日

0 投票

What do you mean "between them"? They're different sizes in the 3rd dimension.
Here, use randperm(). Try this:
m = magic(5) % Sample data
% Get random indexes to pull the new values from.
randomIndexes = randperm(numel(m));
% Assign random locations to new matrix
mNew = reshape(m(randomIndexes), size(m))

2 件のコメント

Lidia
Lidia 2014 年 7 月 6 日
Hi, They are different sizes but they don't need to exchange all the elements. Yeah it worked. Thank you so much! So m(randomIndexes) transforms 'm' to a vector?
Image Analyst
Image Analyst 2014 年 7 月 6 日
Yes. That's "linear indexing" - it gives a 1D vector. So that's why I had to call reshape() - to get it back into the original shape.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by