Matlab to find the sum of each column of matrix A and generate a new matrix

Matlab to find the sum of each column of matrix A and generate a new matrix


B = sum(A)



Matlab sets the elements of matrix whose columns are greater than a certain number to zero
The number of columns in the matrix larger than the minimum value in the column is set to zero


"Set all the numbers in each column of the matrix that are larger than the minimum value in the column to zero", which is equivalent to keeping only the minimum value in each column?
A = rand (5,4);% test data
M = min (a);% to find the minimum value of each column
M = repmat (m, size (a, 1), 1);% copy the minimum value by row and have the same dimension with the original matrix
A (a > m) = 0% set the number of columns larger than the minimum value to zero



How to find the number of different elements in a matrix in MATLAB
If the matrix A = [1 2 3 5 2 3 5 3 2], then the total number of different elements is 4, and these elements are 1, 2, 3, 5. How can we use the function to realize it? Is there no need to loop? Is there any ready-made function?


Using unique function
>> unique([1 2 3 5 2 3 5 3 2])
ans =
1 2 3 5