2

In my cell array test = cell(1,2,20,14); I want to find numeric values in the subset test(:,1,1,1).

For example test(:,:,1,1) looks like this:

>> test(:,:,1,1)

ans = 

[     0]    [0.1000]    [57]
[0.9000]    [0.9500]    [73]

I want to find the index of the cell containing 0.9 in the first column, so I can access the third column (in this case value 73). I tried:

find(test{:,:,1,1} == 0.9) which gives:

Error using == Too many input arguments..

How can I find the respective index?

Thanks.

2 Answers 2

2

Try this to access that third column value directly -

cell2mat(test(vertcat(test{:,1,1,1})==0.9,3,1,1))

Edit 1: If you would like to test out for match w.r.t. the first two columns of test's subset, use this -

v1 = reshape(vertcat(test{:,[1 2],1,1}),[],2)
cell2mat(test(ismember(v1,[0.9 0.95],'rows'),3,1,1))
Sign up to request clarification or add additional context in comments.

2 Comments

Really nice! Could you also extend this code to two conditions like: Give me third column where first column == 0.9 and second column is 0.95?
@PeterRussel Check out Edit 1 !
1

Just add brackets [] around test{:,:,1,1}. This wraps the different cell values together to one vector/matrix. Like this:

[index1, index2] = find([test{:,:,1,1}] == 0.9)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.