MATLAB: Find a value & store in new variable

findsavevariable

Hi,
Standard question:
We have a cell array A cell with integer and decimal numeric values:
A = {[1;2;29;2],[3;4;0.3;3]}
(this is just an example, of course)
We would like to find all occurrences of [2] in column 1, and save corresponded value in column 2 in a new variable "new_variable". In this case "new_variable" would contain [4] and [3], and we could make statistics on this new variable alone, without bothering about the rest.
find(ismember(A{1,1},[2]))
would of course just give us the row coordinates of column 1.
Any suggestion?
Thank you very much!

Best Answer

new_variable = A{2}(find(ismember(A{1,1},[2])))