Find values in 3d matrix

Pavlin

I would like to do the equivalent of

x = [1, 0, 3; 2, 3, 0; 0, 0, 3];
[yy, xx, vals] = find(x);

where I really need the vals variable. I need all three, but vals is important. Now consider the 3d case, and flip one, so it's more interesting.

x = repmat(x, [1, 1, 3]);
x(:, :, 2) = fliplr(x(:, :, 1));

I'd like to do the same as before. I found this in several places

[yy, xx, zz] = ind2sub(size(x), find(x));

but then I don't know how to extract vals properly... I also don't really care about zz, but I'm sure they somehow need to be used for indexing.

Any help would be appreciated.

Cris Luengo

find with one output argument, as you used in your last statement:

[yy, xx, zz] = ind2sub(size(x), find(x));

returns linear indices into the matrix. You can use these to index:

index = find(x);
vals = x(index);
[xx,yy,zz] = ind2sub(size(x), index);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to find N values of 3D matrix that satisfy condition

Find two MAXIMUM values' position in 3D matrix (MATLAB)

Find indices in a 3D matrix

Eigen values of 3D matrix

Python: Find max value along one axis in 3d matrix, make non-max values zero

Find consecutive values in 3D array

How to find the plane of intersection betweeen a plane and a 3d matrix

Obtaining values from a 3D matrix based locations in a 2D matrix

Find summary of values contained in a matrix in python3

MATLAB: extract values from 3d matrix at given row and column indcies using sub2ind 3d

Count all values in a 2D matrix greater than a value for a 3D array

Find the Transformation Matrix that maps 3D local coordinates to global coordinates

Efficient way to find rows with same elements in a 3D matrix in C

How can I find the minima of a 3D matrix in a given dimension?

Creating a 3D Matrix in R based on the presence of some specific values in groups of data in a data set

Applying 3D rotation matrix to x, y, z values obtained from surface function

extract 3D matrix's columns based on "surface" values - vectorization

Find values for which matrix becomes singular in Python

Function to find N greatest values of a matrix rows

Find the x minimal values in a distance matrix in R

find row indices of different values in matrix

How to find high values in the correlation matrix?

How to find p values for correlation matrix in R?

Find the corresponding row ID and column ID of top 3 values in a matrix in excel

Given a 2D matrix of size MxN with positive integer values, find the closed loop that has the maximum sum

R: Find the values of a 2D function (given by a matrix) along an arbitrary line

How to find the nearest values in a list of 3D arrays using numpy?

Python: find consecutive values in 3D numpy array without using groupby?

How to find min and max values in a 3d array in numpy, and group the results?