I’m trying to examine on which rows a particular value is located in a cell, then retrieve the rows in those positions from another cell and put them into a variable.
My data is like:
1x4 Cell =
A B C D %Cell labels for clarity
{10x1 Cell} {10x1 Cell} {10x1 Cell} [10x1 Double]
B blue M 4.78
R red N 6.43
R red N 6.89
B blue M 7.99
B blue M 5.87
B blue M 4.78
R red N 6.43
R red N 6.89
B blue M 7.99
B blue M 5.87
So for example, it would go like this: 1) search for the rows on which "blue" is located in B, 2) “blue” is found to be in rows 1, 4, 5, 6, 9 and 10. Then 3) extract rows 1, 4, 5, 6, 9 and 10 from another datacell, C, to a new variable.
As far as I am aware, logic operations like == may not be sufficient for what I want to do. Which functions should I be looking at to achieve this?
Thanks
Try this:
Explanation:
repmatmakes a cellarray of ‘blue’ with a size of Bisequalcompares the content of two cellscellfunrepeats for all cells and returns logical columnC(...)indexes C with this column and returns matching rowsRegards