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

 Réponse acceptée

Image Analyst
Image Analyst le 6 Juil 2014
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 commentaires

Lidia
Lidia le 6 Juil 2014
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 le 6 Juil 2014
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by