Using logical indexing on a specific set of rows in MATLAB

browser

I want to return the rows in a cell array which meet a condition that is repeated every few (but variable) lines. For example if my data is x,y,z coordinates split up into i slices where each slice{i} is a specific z I could have something that looks like this.

1,3,10
1,4,10
1,5,10
2,3,10
2,4,10
3,1,10

For each x I want to return the rows containing the max and min y values. So in this case I want rows 1, 3, 4, 5, 6.

The code I have now looks like this

idx = slice{i}(start:finish,2) == miny | slice{i}(start:finish,2) == maxy;
return = slice{i}(idx, :);

But the line slice{i}(idx, :) looks through the entire array from the beginning. I want to restrict this line to a certain subset.

Something like

slice{i}(idx, start:finish)

but this doesn't work.

Am I missing some syntax or do I need to approach the routine in a different way? (I know I haven't provided enough information for help in changing approach but I am assuming there is some way to do this by restricting the row indicies)

edit:

I found a workaround by creating

dummy = slice{i}(start:finish, :);    

and then just returning over the dummy matrix.

Divakar

See if this works for you -

%// Convert slice to a nuemric array
slicenum = cell2mat(slice)

%// Create the offset arary to be added with the local max-min indices to
%// get the global(actual) row indices for idexing into slicenum or slice
offset1 = [0 ; find(diff(slicenum(:,1)))]

[~,~,unqX] = unique(slicenum(:,1))

%// Get local max and min row indices
max_row_ind = accumarray(unqX,slicenum(:,2),[],@max_ind) + offset1
min_row_ind = accumarray(unqX,slicenum(:,2),[],@min_ind) + offset1

%// Get global row indices and use them to index into slicenum for the output
max_y_slice = slicenum(max_row_ind,:)
min_y_slice = slicenum(min_row_ind,:)

Associated functions -

function ix = max_ind(array1)
[~,ix] = max(array1);
return;

function ix = min_ind(array1)
[~,ix] = min(array1);
return;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Matlab - remove image border using logical indexing

From Dev

indexing rows in matrix using matlab

From Dev

indexing rows in matrix using matlab

From Dev

Matlab: Remove IF-ELSE Conditional statements using Logical Indexing

From Dev

Deleting a specific rows and columns from a data-set using Matlab

From Dev

Logical indexing using a vector

From Dev

Logical indexing in Numpy with two indices as in MATLAB

From Dev

Logical indexing of chars in heterogenous cell array in MATLAB

From Dev

MATLAB "element-wise" logical indexing

From Dev

Matlab: Multiple assignment through logical indexing

From Dev

Logical-Indexing for Matlab-object-arrays

From Dev

Find local maxima with logical indexing in MATLAB

From Dev

Logical indexing of chars in heterogenous cell array in MATLAB

From Dev

How to get mean values of certain regions in each slice in 3d matrix using logical indexing MATLAB

From Dev

Matlab : If 'A' is an indexed variable, performance can be improved using logical indexing instead of FIND

From Dev

comparing rows of a logical matrix in matlab?

From Dev

Pandas logical indexing using multiple conditions

From Dev

How to perform logical operation and logical indexing using VIPS in Python?

From Dev

Splitting an image into two parts (background / foreground) with logical indexing in Matlab

From Dev

Matrix indexing using vectors in Matlab

From Java

pandas apply only returning first value when using logical indexing

From Dev

What is the correct syntax for using logical or boolean indexing with Pandas DataFrames?

From Dev

What is the correct syntax for using logical or boolean indexing with Pandas DataFrames?

From Dev

Creating a new column in panda dataframe using logical indexing and group by

From Dev

How can I replace a matrix element using logical indexing?

From Dev

ddply() and using length to count within a specific set of rows in R

From Dev

ddply() and using length to count within a specific set of rows in R

From Java

Inequality indexing using optimization variables in MATLAB

From Dev

Matlab: extracting rows with specific datetime

Related Related

  1. 1

    Matlab - remove image border using logical indexing

  2. 2

    indexing rows in matrix using matlab

  3. 3

    indexing rows in matrix using matlab

  4. 4

    Matlab: Remove IF-ELSE Conditional statements using Logical Indexing

  5. 5

    Deleting a specific rows and columns from a data-set using Matlab

  6. 6

    Logical indexing using a vector

  7. 7

    Logical indexing in Numpy with two indices as in MATLAB

  8. 8

    Logical indexing of chars in heterogenous cell array in MATLAB

  9. 9

    MATLAB "element-wise" logical indexing

  10. 10

    Matlab: Multiple assignment through logical indexing

  11. 11

    Logical-Indexing for Matlab-object-arrays

  12. 12

    Find local maxima with logical indexing in MATLAB

  13. 13

    Logical indexing of chars in heterogenous cell array in MATLAB

  14. 14

    How to get mean values of certain regions in each slice in 3d matrix using logical indexing MATLAB

  15. 15

    Matlab : If 'A' is an indexed variable, performance can be improved using logical indexing instead of FIND

  16. 16

    comparing rows of a logical matrix in matlab?

  17. 17

    Pandas logical indexing using multiple conditions

  18. 18

    How to perform logical operation and logical indexing using VIPS in Python?

  19. 19

    Splitting an image into two parts (background / foreground) with logical indexing in Matlab

  20. 20

    Matrix indexing using vectors in Matlab

  21. 21

    pandas apply only returning first value when using logical indexing

  22. 22

    What is the correct syntax for using logical or boolean indexing with Pandas DataFrames?

  23. 23

    What is the correct syntax for using logical or boolean indexing with Pandas DataFrames?

  24. 24

    Creating a new column in panda dataframe using logical indexing and group by

  25. 25

    How can I replace a matrix element using logical indexing?

  26. 26

    ddply() and using length to count within a specific set of rows in R

  27. 27

    ddply() and using length to count within a specific set of rows in R

  28. 28

    Inequality indexing using optimization variables in MATLAB

  29. 29

    Matlab: extracting rows with specific datetime

HotTag

Archive