I need to randomly scramble the values of an nx1 matrix in matlab. I'm not sure how to do this efficiently, I need to do it many times for n > 40,000.

Example

Matrix before:

1 2 2 2 3 4 5 5 4 3 2 1

Scrambled:

3 5 2 1 2 2 3 4 1 4 5 2

thank you

If your data is stored in matrix `data`

, then you can generate "scrambled" data using randperm like so:

```
scrambled = data(randperm(numel(data)));
```

This is sampling *without* replacement, so every value in `data`

will appear once in `scrambled`

.

For sampling *with* replacement (values in `data`

may appear in `scrambled`

multiple times and some may not appear at all), you could use `randi`

like this:

```
scrambled = data(randi(numel(data),1,numel(data)));
```

Similar Questions

Lets say I have a 3x3 matrix and a 3x1 vector, I want to multiply my matrix A with vector P multiple times. A=[0 0.3 0.5; 0.8 0 0.5; 0.2 0.7 0] * P=[1; 1; 1] I want to multiply the answer of this wi

I want to use some big matrix that can't fit in RAM memory.My matrix is not sparse. I need this for some batch\chunk processing or online machine learning algorithms. What I need: 1.Read some chunk o

How in Matlab we can form a matrix X, 1000 by 1000, which is sparse with, say, 5% of independent Bernoulli +-1 nonzero entries? I.e. such a matrix would have rho = ||X||_0/10^6 = 0.05.

I have one matrix *u_test* that contains the data from my test set. It's formats is like that: X y value 1 3 5.0 1 6 3.4 4 3 2.0 I want to create a matrix test from *u_test*, so that the value of the

I need to make a matrix/vector multiplication in Matlab of very large sizes: A is an 655360 by 5 real-valued matrix that are not necessarily sparse and B is a 655360 by 1 real-valued vector. My qu

I am calling the Google Protocol Buffers Java API from Matlab. This works pretty well, but I have hit a big performance bottleneck. The bulk of the data are returned as objects of type: java.util.Coll

This question already has an answer here: MATLAB: Create a block diagonal matrix with same repeating block 2 answers Matlab syntax question : Given some n x d matrix A(say [1 2 3; 4 5 6]), and

Given two set of d-dimensional points. How can I most efficiently compute the pairwise squared euclidean distance matrix in Matlab? Notation: Set one is given by a (numA,d)-matrix A and set two is giv

How to turn a matrix into a vector row-wise efficiently. Example: >> a = [1 2; 3 4] a = 1 2 3 4 the (:) notation gives me: >> a(:) ans = 1 3 2 4 but I want to get the result as this: >

Hi I have problem with matrix.. I have many .txt files with different number of rows but have the same number of column (1 column) e.g. s1.txt = 1234 rows s2.txt = 1200 rows s2.txt = 1100 rows I want

I wonder if there is a Matlab solution to split a matrix into sub matrices like the following: The matrix is: A = 16 2 3 5 11 10 9 7 6 4 14 15 5 1 3 I would like to take the rows those starting with

Is there any way for me to access specific matrix in the concatenate? For example: a = [1,2,3,4:5,6,7,8:9,0,1,2]; b = [3,2,1:4,2,1:5,6,7]; c = [a b]; I wish to access the matrix b from c.. It is very

This problem is probably less to do with Matlab and more to do with matrix algebra (which I mostly forget from my college courses). Say I have a m x n matrix X and a m x 1 matrix B. How would I divide

I have a matlab matrix in the form A = [1 2 3 4 5 6; 1 1 2 2 3 3; 1 2 3 3 2 1] Is it possible to delete the 4th, 5th and 6th columns of the matrix A so that the result would be: A = [1 2 3; 1 1 2; 1

I was wondering how can matlab multiply two matrices so fast. When multiplying two NxN matrices, N^3 multiplications are performed. Even with the Strassen Algorithm it takes N^2.8 multiplications, whi

I am trying to replace the first and second column of an edgelist matrix (edgenumber x 3) by specific node numbers as such: 5 1 1 1 38 1 2 1 1 28 17 1 18 1 1 25 1 1 that the node numbers (connection

I have a problem with matrix dimension and the find function. For each row, I'm trying to find the index related to the value greater than 20 and store the result in another matrix. For example: A =

I have two curves with sizes: size(A) = 1 312 and size(B) = 312 When subtsracting A from B, I got this error message Error using ==> minus Matrix dimensions must agree. Can this error be attri

How can i randomly pick a number from the given following matrix below? A=[0.06 0.47 0.47] I just want to randomly pick a number from the matrix above. I am doing this in matlab enviornment. please

Possible Duplicates: MATLAB Easiest way to assign elements of a vector to individual variables. How do I do multiple assignment in MATLAB? If I have a matrix: A = [1, 5, 10], do I set a1 = A(1), b1

I need to create a list (of size n) of random, non-repeating set of coordinates on a matrix of predefined size. Is there a fast way to generate this in Matlab? My initial idea was to create a list of

I have array (vector) r =[2 4] and report matrix with size 50*2. I want put r in row 1 of report matrix. When I run with report(1)=r; MATLAB returns this error: ??? In an assignment A(I) = B, the nu

I want to make 1000 random permutations of a vector in matlab. I do it like this % vector is A num_A = length(A); for i=1:1000 n = randperm(num_A); A = A(n); % This is one permutation end This takes

In a project, I need to perform power() function on RGB matrix in a matlab GUI program, but matlab keeps returning error meesage. Below is the code and the error message img_src = getappdata(handles.f

Suppose I have a Matlab matrix A(x,y) which is square matrix with size N+1. I want a new matrix B, whose element B(x,z) is A(x,N-x-z), and in case x+z>N, B(x,z) is just zero. Of course I can do it

I have an AxB matrix and two binary column vectors, Ax1 and Bx1 in Matlab. How can i select the rows of the matrix corresponding to 1 of Ax1 vector? Obviously, I have to do the same operation on the c

Say I have three different 2x2 submatrices, and I want to create a big 6x6 matrix in Matlab in which the three submatrices appear on the diagonal, and all the other values are 0. How can I do this wih

I have an X matrix of dimensions 37,000,000 by 22, and I want to compute the correlation matrix of X. I.e., X_corr = corr(X,'type','Spearman'); And I'd like the size of X_corr to be of 22 by 22. But

I am a beginner to matlab. I have a sample code. I want to understand what is happening with the piece of code snippet. Sample.m n=60;%Number of division of length m=84;%Number of division of time N=

I have the following nX1 matrix, here n is very large, I want to carry out the following operation- (2nd term) minus (first term) ,that is (2.25555-1.45656),(4.74096-2.25555),(440.0000-4.74096) and so

I want to create a matrix in matlab with 500 cell (50 row,10 column ), How I can create and initialize it by random binary digits? I want some thing like this in 50*10 scale as sample 3*4 0 1 1 1 0 0

I want to generate a matrix of random numbers (normrnd with mean == 0) that satisfy the following constraints using MATLAB (or any other language) The sum of the absolute values in the matrix must eq

in following code I'm disappointed because I want to let matlab do what I able to do per hand. This code is actually working well, if I write it by hand for every step, which is of course absoulte sil

I know there are packages in R to store sparse matrices efficiently. Is there also a way to store a low-rank matrix efficiently? For example: A <- matrix(rnorm(1e6), nrow=1e5, ncol=1e1) B <- A %

I want to get a vector of elements of a Matlab matrix at predefined locations. For example, I have the following >> i = [1,2,3]; >> j = [1,3,4]; >> A = [1,2,3,4; 5,6,7,8; 9,10,11,12;

I am trying to aquire image using a camera connected to the Matrix Vision frame grabber in Matlab. However, when I type imaqhwinfo, I see the installed adaptors as 'coreco' and 'winvideo'. When I chec

Anyone know a quick efficient way in matlab to build the following square matrix 1 -1 0 0 0 0 -1 2 -1 0 0 0 0 -1 2 -1 0 0 0 0 -1 2 -1 0 0 0 0 -1 2 -1 0 0 0 0 -1 1 Which has 2's on the diagonal excep

I have this huge sparse matrix A of size 2 million by 10 thousand. I want to index particular 1000 rows (index) from this matrix. If I do B = A(index,:); it takes some time. Is there a better quick

I have set of points (matrix Nx1) and groups for this points (matrix Nx1). I want to plot this points (there is no problem, I do this like this: plot(points, groups, 'o');), but I'd like to set unique

How to export any size matrix like A= 1 2 3 4 5 6 ....9 3 6 7 8 9 9 ....4 ... 6 7 7 4 4 5 ... 2 To a file that will contain that matrix where each value is separated by ',': 1, 2, 3, 4, 5, 6, ....,9

My problem is this: I've a matrix, as example 1 2 3 4 2 6 6 1 8 4 5 4 7 1 5 8 2 0 I wish to extract selected values from the matrix, as example, a vector like this B = [3 6 0] selecting third column

I have a matrix in Matlab where each row looks something like this: 1 3 0.112 5.31275 4.61924 -6.50652 And I want to extract to different matrices according to the value presented in the first column

I have a matrix which is 36 x 2, but I want to seperate the elements to give me 18, 2 x 2 matrices from top to bottom. E.g. if I have a matrix: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ... ... I want to spli

I have a martix and want to shuffle element of it . x=[1 2 5 4 6 ] after shuffle(something like this) x=[2 4 6 5 1] is matlab has function for it ? in php array_shuffle do this.

I have a x by y matrix, where each row and each column are in ascending order as given below. 1 5 7 9 4 6 10 15 8 11 12 19 14 16 18 21 How to search this matrix for a number in O(x+y)? I was asked th

Is there a fast way to remove rows and columns from a large matrix in MATLAB? I have a very large (square) distance matrix, that I want to remove a number of rows/columns from. Naively: s = 12000; D =

I'm involved in the resolution of a system of the type Ax = b, where A is a square sparse matrix, x is the vector of the unknows (I have to compute it) and b is a vector of all zeros excpet for the la

I've been wondering about this question for quite a while but cannot find a reference: How does Matlab transpose a sparse matrix so fast, given that it is stored in CSC (compressed sparse column) form

I've seen several examples of fsolve in matlab, but can't seem to find any that show how to pass parameters in matrix form. Here is my code. [A,b] = equationsToMatrix(eq1,eq2) X0 = [0 0] fsolve([A,b],

I am doing the dot product of two 3x11 matrices in MATLAB, these matrices are multidimensional but I am only accessing one 'page' at a time. From my maths knowledge I would expect a 3x11 matrix back a