MATLAB: How to randomize the rows of a matrix? [duplicate] - matlab

This question already has answers here:
Random order of rows Matlab
(4 answers)
Closed 7 years ago.
I'm looking for an efficient way to manipulate a 40x151 matrix so that the rows are randomly scrambled.

I worked out the answer just as I was about to post.
new_matrix = old_matrix(randperm(40),:)

Related

Swift random element with probability [duplicate]

This question already has answers here:
Generate random numbers with a given distribution
(4 answers)
how to generate random numbers from 1 to 4 and 8 in swift
(2 answers)
Closed 4 months ago.
It seems like randomElement() in Swift only allows for an equally weighted selection. What would be the best (and most efficient way, as I need to repeat this very often) to select from a collection with pre-specified probabilities/weights?

knn compare 2 images matlab [duplicate]

This question already has answers here:
Image comparison - fast algorithm
(12 answers)
Image similarity comparison
(7 answers)
Closed 5 years ago.
I need a help. I don't know how to write a Matlab/Java code compare 2 images using KNN, the result should take "wrong" when image 2 is different than image 1. I have to imporve displacement between x1,x2,x3 and that each subsequent generated image with the same x1,x2,x3 is invalid (Prove that the diameter has increased). Others compare it with histograms. Anybody will help me?

name matrix as A1 to A50 automatically [duplicate]

This question already has answers here:
Create variables with names from strings
(6 answers)
How to Dynamically Create Variables in MATLAB [duplicate]
(3 answers)
Closed 5 years ago.
I run an algorithm that result of it is a matrix as A. I run an algorithm 50 times and I want to save results as A1 to A50 matrix. how can I write?

how to rearrange each block into a column vector? [duplicate]

This question already has answers here:
Efficient Implementation of `im2col` and `col2im`
(2 answers)
Closed 7 years ago.
example: I have an image,it's size 512X512pixel,then i have splited it into 8x8 blocks.Now i would have 64x64 blocks.Now how to rearrange each block 8x8 into column vector so that the dimension would be 64x4096pixel without inbuilt function "im2col".please help me out.
Thanks.
x=rand(512,512);
xi=mat2cell(x,8*ones(1,64),8*ones(1,64));
xii=cellfun(#(x)reshape(x,1,64),xi,'UniformOutput',false);
y=cell2mat(xii);

How can I repeat matrix? [duplicate]

This question already has answers here:
how to replicate an array
(4 answers)
Closed 8 years ago.
Could you help me please to repeat matrix. for example if I have matrix(A) and I want to create a big matrix(B) contains three matrices of matrix(A) in the row and two matrices in the column.
The MATLAB function repmat does exactly what you need:
B = repmat(A,3,2);
For more details see the MATLAB documentation
In MatLab, you want to use repmat().
In Python, use the Numpy function, tile(a, (m, n)).
You should check out this post: https://stackoverflow.com/a/1724410/515559