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

 采纳的回答

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 个评论

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?
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 Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by