Find a new matrix considering the values of one of the columns - matlab

I have a m-rows by n-columns matrix in matlab. One of the columns (#2) contain the values of VIP and I want to obtain the matrix that only contain the rows of the original matrix where VIP>1.
How can I find this new matrix?

Related

MATLAB Sum along some columns within 3D matrix

Let's assume I have a 8x6x2 matrix signals. I would like to sum along the columns excluding the first column. When using the following code, MATLAB concatenates the 3D matrix to a big 2D (8x11) matrix, which is different from the result I am looking for.
sum(signals(:, 2:end), 2)
I am actually looking for a 8x1x2 3D vector comprising the sums of column 2 to six from each third dimension.
Since your matrix is a 3D matrix, you need to include a colon as the third subscript in your indexing. If you only specify two subscripts, then MATLAB will collapse all trailing dimensions into the last dimension you've specified.
sum(signals(:, 2:end, :), 2)

Creating sparse matrix within a loop

I want to make a sparse matrix from a graph which is stored in an Mx2 matrix:
for i = 1:m
adj = sparse(Graph(i,1), Graph(i,2), 1);
end
But adj only keeps one value. I don't know how big adj will be prior to the loop.
How can I tell MATLAB to create this sparse matrix?
No for loop is necessary. The sparse function takes in a vector of non-zero row locations, a vector of non-zero column locations and a vector of non-zero values. If all of the values are the same, you can simply use a scalar value to initialize all of them at once.
Simply do this1:
adj = sparse(Graph(:,1), Graph(:,2), 1);
This accesses all of the row locations with Graph(:,1), the column locations with Graph(:,2) and finally we initialize all values at these locations to 1.
This is also assuming that you have non-duplicate row and column locations in Graph. If you do have duplicate row and column locations, the non-zero values defined at these locations are accumulated into the same locations. For example, if we had three instances of (6,3) in our matrix, the output at this location in the sparse matrix would be 3.
1. Credit goes to Luis Mendo for initially proposing the answer

How to generate a random orthogonal matrix with constant magnitude complex entries

I would like to generate a random matrix that
Its columns are orthogonal to each other.
The entries of each column are complex values with constant magnitude.
As an example the DFT matrix has orthogonal columns and all the elements have absolute value of one. How can I generate some other random matrices with the same properties?

Extracting some rows and columns

I was wondering if there is a way to subset a matrix in EIGEN into another Matrix based on some condition.
For example in MATLAB, one can do this: Let A be a matrix of size 5-by-5.
B=A(1:3,2:3)
This will create a new matrix B from A with dimensions 3-by-2 and with elements from A at the relevant indices.

Averaging Binned Values

I have an NxM matrix where I am binning on the first column into n buckets. What I would like to know is if I would like to take the average of all values in the secondary columns of my matrix is this possible.
So basically what I want is if I have a 2x1000 matrix where I bin on the data for the first column, I'd like to be able to average all values in each bin based on the second column of my matrix.
Perhaps a function exists that will easily allow me to do this. I appreciate any input.