0

I have the following array:-

dir=['E','B','R']

I want to find the index of the elemen 'E'.

>> find(dir=='E')

ans =

     1

But i want to do the same for an array of strings rather than array of characters like:

dir=['E','G','T','BR']

But there is an error to find 'BR'. I want the output to be 4.

>> find(dir=='BR')
Error using  == 
Matrix dimensions must agree.

How to work-around this error?

1 Answer 1

3

I recommend you look at the documentation on string (char array) handling in matlab such as here.

What you want to do is work with cell arrays of strings:

 dir = {'E','G','T','BR'}
 find(ismember(dir,'BR'))

 ans = 4
Sign up to request clarification or add additional context in comments.

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.